Home > DeveloperSection > Forums > Set a character variable with an if - then statement
Jayden Bell
Jayden Bell

Total Post:105

Points:739
Posted on    June-11-2013 7:02 AM

 VB.Net VB.Net 
Ratings:


 1 Reply(s)
 621  View(s)
Rate this:
Hi Expert,

How to set a variable, typeofauction, as either 'a' or 'f' with an if then statement. dim typeofauction as char. I'm trying as following 

typeofauction = typeofauction1.Text
    If (typeofauction = "Auction") Then
        listingtype = 'a'
    End If
    If (typeofauction = "Fixed Price") Then
        listingtype = 'f'
    End If

What wrong with above line of code.
Please help.
Thanks in advance. 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-12-2013 8:02 AM

Hi Jayden,

You say you are trying to set typeofauction, which is defined as a char type, to 'a' or 'f'. However, your code shows you are trying to set listingtype which appears to be a char.

I think you have your types confused. Try:

Dim listingtype As Char

Dim typeofauction As String = typeofauction1.Text ' assuming this is a textbox

If typeofauction = "Auction" Then
   listingtype = "a"c
ElseIf typeofauction = "Fixed Price" Then
   listingtype = "f"c
End If

You don't have to use the Char type for listingtype. You can also use a String which will simply hold only one character.

Don't want to miss updates? Please click the below button!

Follow MindStick