g46905
asked on
comparing the strings in VB.NET
Please look at the code below and follow the arrow mark.
Me.cmbRole.SelectedItem returns either 'user' or 'group' or 'others'.If it returns users, then 1 shoud be stored in usr.USER_TYPE ,if 'group' then 2, and if 'others' then 3 likewise.I am relatively new to this language and I haven't worked on string manipulations.Can you please help me achieve the task.Please let me know if you have any questions.Thannks a lot!
Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
Dim usr As User = New User
If (Me.cmbRole.SelectedIndex > -1) Then
usr.USER_TYPE = Me.cmbRole.SelectedItem <<------------------------ ---------- ---------- -
End If
usr.WP_USER_ID = 6 'Me.tbUserId
usr.TNUMBER = Me.tbUserId.Text.Trim
User.SetUser(usr)
End Sub
Me.cmbRole.SelectedItem returns either 'user' or 'group' or 'others'.If it returns users, then 1 shoud be stored in usr.USER_TYPE ,if 'group' then 2, and if 'others' then 3 likewise.I am relatively new to this language and I haven't worked on string manipulations.Can you please help me achieve the task.Please let me know if you have any questions.Thannks a lot!
Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click
Dim usr As User = New User
If (Me.cmbRole.SelectedIndex > -1) Then
usr.USER_TYPE = Me.cmbRole.SelectedItem <<------------------------
End If
usr.WP_USER_ID = 6 'Me.tbUserId
usr.TNUMBER = Me.tbUserId.Text.Trim
User.SetUser(usr)
End Sub
oops:
if (Me.cmbRole.SelectedItem.e quals("use r")) then
usr.USER_TYPE = 1
elseif
...
end if
if (Me.cmbRole.SelectedItem.e
usr.USER_TYPE = 1
elseif
...
end if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is this a web app, or a windows app? The answer might be simpler if it is a web app. Anyway...
Select Case Me.cmbRole.SelectedItem
Case "user"
user.USER_TYPE = 1
Case "group"
user.USER_TYPE = 2
Case "others"
user.USER_TYPE = 3
End Select
Select Case Me.cmbRole.SelectedItem
Case "user"
user.USER_TYPE = 1
Case "group"
user.USER_TYPE = 2
Case "others"
user.USER_TYPE = 3
End Select
Could you not use:
usr.USER_TYPE = Me.cmbRole.SelectedIndex - 1
This assumes your combobox items are in this order: users, group and others
bobbit's post is an alternative to your solution, and the advantage is that it is based on proper values, rather than assumed index positions
usr.USER_TYPE = Me.cmbRole.SelectedIndex - 1
This assumes your combobox items are in this order: users, group and others
bobbit's post is an alternative to your solution, and the advantage is that it is based on proper values, rather than assumed index positions
usr.USER_TYPE = 1
elseif
...
end if