Advertise with us

Set a character variable with an if - then statement

Posted by  Jayden Bell
 1382  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. 
  1. Re: Set a character variable with an if - then statement

    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.

      Modified On Mar-30-2018 02:29:57 AM