我正在尝试使用if then语句将变量typeofauction设置为“a”或“f”。 dim typeofauction as char
typeofauction = typeofauction1.Text
If (typeofauction = "Auction") Then
listingtype = 'a'
End If
If (typeofauction = "Fixed Price") Then
listingtype = 'f'
End If
我做错了什么?
答案 0 :(得分:2)
您说您试图将typeofauction
(定义为char
类型)设置为“a”或“f”。但是,您的代码显示您尝试将listingtype
设置为char
。
我认为你的类型很混乱。尝试:
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
您没有 使用Char
类型listingtype
。您也可以使用String
,它只能容纳一个字符。
答案 1 :(得分:0)
您刚刚声明typeofauction as char
,因此它只接受一个字符。
您需要按如下方式声明:
Dim typeofauction as String
因为“Auction”和“FixedPrices”是字符串。