Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


comparing the strings in VB.NET

Posted on 2005-04-28
Medium Priority
Last Modified: 2010-05-18
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

End Sub
Question by:g46905
  • 3
LVL 18

Expert Comment

ID: 13889063
if (Me.cmbRole.SelectedItem.equals("user") then
  usr.USER_TYPE = 1
end if
LVL 18

Expert Comment

ID: 13889066

if (Me.cmbRole.SelectedItem.equals("user")) then
  usr.USER_TYPE = 1
end if
LVL 18

Accepted Solution

bobbit31 earned 500 total points
ID: 13889077
sorry for multi-posts but you may need to convert SelectedItem to string:

if (Me.cmbRole.SelectedItem.toString().equals("user")) then
  usr.USER_TYPE = 1
end if

Expert Comment

ID: 13889098
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
LVL 12

Expert Comment

ID: 13889103
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question