Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting program to read the left two characters of a textbox 2

Status
Not open for further replies.

lunaclover

Programmer
Jun 22, 2005
54
Alright, this sounds easy enough, right?

Here's what I'm trying to do... I have several if/elseifs/elseif nested in other if/elseif/elseif conditionals. Once a model number is built (txtmodelnumber) it fills the textbox (whose text changes during run-time depending on which selections (a combination of radiobuttons and chkboxes))are made and displays (by enabling/disabling) certain available checkbox options (around 40).

Instead of writing a bunch of code based on other selections that generate the model number in the first place, I just want to be able to say

'if the first two characters of the model number are 'DM' (for example), then chk1.enabled = true, chk2.enabled = false, chk3.enabled = true, etc etc', and the checkboxes that are enabled/disabled will change depending on what the first two characters of the already built model number happen to be.

I have searched this site and others, so far I have tried,

txtModelNumber.text.equals(2) = "DM"

and

left(txtmodelnumber.text, 2) = "DM"

and a few other things I won't bore you with. My question - what is the correct format for doing this?

Thanks for your help or any direction you could give me.

Luna

 
Luna, do you mean something like this:

Code:
    chkAB.Checked = False
    chkCD.Checked = False
    chkEF.Checked = False
    chkGH.Checked = False
    chkOther.Checked = False

    Select Case TextBox1.Text.Substring(0, 2).ToUpper
      Case "AB"
        chkAB.Checked = True
      Case "CD"
        chkCD.Checked = True
      Case "EF"
        chkEF.Checked = True
      Case "GH"
        chkGH.Checked = True
      Case Else
        chkOther.Checked = True
    End Select

Hope this helps.

[vampire][bat]
 
That absolutely works, earthandfire! Thank you so much for leading me in the right direction!

Luna
 
earthandfire,
I was doing a similar one yesterday by converting VBA to VB.NET (2005 express)
VBA part was
Code:
Left(txtBox,2)
converted to
Code:
Microsoft.VisualBasic.Left(txtBox, 2)
with the help of help file.

My question is which one is new or best for .net ?
Microsoft.VisualBasic.Left() ? or
TextBox1.Text.Substring() ?

________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
The substring is the .net way.



Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Thanks chrissie..


________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
Zameer, whilst I agree with chrissie, I don't think there is anything wrong with using Left if you are happier that way. Microsoft examples use Left so why shouldn't we if we want to? I just think Substring is neater and personally prefer it.

[vampire][bat]
 
And Substring is also available from other languages that use the framework (e.g C#).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
So Left is not obsolete..
Ofcourse one can't use Left(.....)alone .net for this. he must use Microsoft.VisualBasic.Left while Left() alone considered as control's left edge.
help said:
Gets or sets the distance, in pixels, between the left edge of the control and the left edge of its container's client area.


________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
he must use Microsoft.VisualBasic.Left while Left() alone considered as control's left edge
Basically, yes but as I said above, personally I prefer substring as it is a true part of the framework (I couldn't use the above function in a C# application).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here .net speaks a common language[wink]

________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
But then again you can import microsoft.visualbasic in a c# application. So feel free to do what ever you like afterall it has just been christmas and we are all still in the spirit.

Sorry E&F but modules still aren't allowed.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
chrissie1 said:
.....afterall it has just been christmas and we are all still in the spirit.

Christmas spirit? or Bottle of spirit?




________________________________________________________
Zameer Abdulla
Help to find Missing people
Education's purpose is to replace an empty mind with an open one.
~Malcolm S. Forbes~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top