Concatenation of values shown in a textbox

mozaharul

Active Member
Licensed User
concatenating textboxes values combox value in another textbox

I have 2 text box and 2 combo box added in a form. I want to show the values of text boxes and combo boxes all together in another text box.

Need help from anyone.:sign0085:


best regards
 

mozaharul

Active Member
Licensed User
Hi,
I want to concatenate digits of 2 textboxes and 2 combo boxes in another textbox. If choose in 1st combo box (cmbstar) value=3, 2nd combo box (cmbclu) value=178 as per my coding and in textbox txthhid.text=222, txtiid.text=555 then txthhidtn.text textbox should show 10 digits like "3178222555", but it shows 9 digits like "317822255". I am totally new to this environment, looking for help


Here is the code for help:

Sub Globals
'Declare the global variables here.
Dim i,cb1,cb2
End Sub

Sub App_Start
Form1.Show
For i = 1 To 7
cmbstar.Add (i)
Next
'txthhidtn.Enabled = false
End Sub

Sub Cmbstar_SelectionChanged (Index, Value)
Select index
Case 0
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 1 To 27
cmbclu.Add (i)
Next
Case 1
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 1 To 14
cmbclu.Add (i)
Next
Case 2
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 1 To 178
cmbclu.Add (i)
Next
Case 3
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 4 To 14
cmbclu.Add (i)
Next
Case 4
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 1 To 82
cmbclu.Add (i)
Next
Case 5
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 5 To 58
cmbclu.Add (i)
Next
Case 6
cmbclu.SelectedIndex = -1
cmbclu.Clear
For i = 1 To 89
cmbclu.Add (i)
Next
End Select
End Sub

Sub txtiid_KeyPress (key)
If StrLength (txtiid.Text) = 2 Then
txthhidtn.SelectionLength = 10
txthhidtn.Text = cb1 & cb2 & txthhid.Text & txtiid.Text
End If
End Sub

Sub txthhid_KeyPress (key)
If StrLength (txthhid.Text) = 2 Then
txtiid.Focus
End If
End Sub

Sub Cmbstar_LostFocus
If cmbstar.SelectedIndex >= 0 Then
cb1=cmbstar.Item (cmbstar.SelectedIndex)
End If
End Sub

Sub Cmbclu_LostFocus
If cmbclu.SelectedIndex >= 0 Then
cb2=cmbclu.Item (cmbclu.SelectedIndex)
End If
End Sub

 

BjornF

Active Member
Licensed User
Dear Mozaharul,

the problem lies in the sub txtiid_keypress(key), the txthhidtn.text is evoked before the final character from the keypress is put into the txtiid box. If you change the strlength value to 3 instead of 2 (which means you have to press an arbitrary key after having entered your number) you will get the correct answer in your txthhidtn box.

Sub txtiid_KeyPress (key)
If StrLength (txtiid.Text) = 3 Then
txthhidtn.SelectionLength = 10
txthhidtn.Text = cb1 & cb2 & txthhid.Text & txtiid.Text
End If
End Sub

all the best / Björn

Edit: I think that if you did want the txthhid to be filled after two keypresses you could start a timer when strlength(txtiid.text)=2, which after a very short time interval could concatenate the full strings - but I haven't tried that one out
 
Last edited:

mozaharul

Active Member
Licensed User
Dear BjornF,
Thanks, but if StrLength (txtiid.Text) = 3, it would add an extra digit or space in the txtiid.text textbox, am I right?
 

BjornF

Active Member
Licensed User
Yes, that is right. However, if you use the solution with a timer you can avoid it:

Sub txtiid_KeyPress (key)
If StrLength (txtiid.Text) = 2 Then
Timer1.Enabled=True
End If
End Sub

Sub Timer1_Tick
Timer1.Enabled=False
txthhidtn.SelectionLength = 10
txthhidtn.Text = cb1 & cb2 & txthhid.Text & txtiid.Text
End Sub

I'm not sure if there are other, more elegant solutions, to it but this one works. (See attached file)

all the best / Björn
 

Attachments

klaus

Expert
Licensed User
Hello Mozaharul,
Here is another solution.
The problem you encountered is that the TextBox.Text is only updated after having left the KeyPress routine.
In the example below, you can enter only numbers in the TextBoxes and BackSpace. It looks more complicated but it uses only string manipulations.
I used two types of selecting the key, one with select case and the other with If then so can also see the difference.
I added also the first value of the 2nd ComboBox as default value.
The result TextBox is continually updated.
It's now up to you to choose the solution depending on what exactly you want to do.

I hope this will clarify the problem.

Klaus
Switzerland
 

Attachments

mozaharul

Active Member
Licensed User
Thanks to all for the help

Thanks for the solution and Your time. May need help in future.

I'm new to this environment.


Thanks again.
 
Top