PDA

View Full Version : Quick Questions [VB]



TheSpectator
01-20-2006, 03:47 PM
In VB how would I write something selected in a combobox to a textbox on the same form. Plus it has to write to certain areas (for example can't be first letter has to be the 19'th 20'th and 22'nd letter on a 50-length text bar. Thanks for your help.

K? Pŕo?ćtiόnŹ
01-20-2006, 04:12 PM
What the **** are you talking about? Give an example.

TheSpectator
01-20-2006, 04:19 PM
Dan']What the **** are you talking about? Give an example.

lol simplified

1) How do I write something into a textbox by selecting someting inside a combobox (drop down list). So when I select "lol" in the combobox it writes lol in a textbox.

2) How do I write to specific parts for example

00000000000000000000000000000000000000000000000000
(50 letters long)
If I select "lol" it writes lol in the 19'th, 20'th and 22'nd letter like so:

000000000000000000lo0l0000000000000000000000000000

K? Pŕo?ćtiόnŹ
01-20-2006, 04:31 PM
lol simplified

1) How do I write something into a textbox by selecting someting inside a combobox (drop down list). So when I select "lol" in the combobox it writes lol in a textbox.

2) How do I write to specific parts for example

00000000000000000000000000000000000000000000000000
(50 letters long)
If I select "lol" it writes lol in the 19'th, 20'th and 22'nd letter like so:

000000000000000000lo0l0000000000000000000000000000
Thats better. It would be a hell of a lot easier if you could do pointer things in VB, I dont know if you can but I dont know how to if you can so it will be a little bit complicated.

Go to the sub that handles the event of an item being selected in the combobox.


sub handler_event(item)
textbox.text=left$(textbox.text,18)+left$(combobox .itemtxt(item),2)+mid$(textbox.text,21,1)+right$(c ombobox.itemtxt(item),1)+right$(textbox.text,len(t extbox.text)-22)
end sub

Something like that.


EDIT: Tested.



Private Sub combo_Click()
txtbox.Text = "------------------------------------------------------------"
txtbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
End Sub

TheSpectator
01-20-2006, 05:45 PM
Dan']Thats better. It would be a hell of a lot easier if you could do pointer things in VB, I dont know if you can but I dont know how to if you can so it will be a little bit complicated.

Go to the sub that handles the event of an item being selected in the combobox.


sub handler_event(item)
textbox.text=left$(textbox.text,18)+left$(combobox .itemtxt(item),2)+mid$(textbox.text,21,1)+right$(c ombobox.itemtxt(item),1)+right$(textbox.text,len(t extbox.text)-22)
end sub

Something like that.


EDIT: Tested.



Private Sub combo_Click()
txtbox.Text = "------------------------------------------------------------"
txtbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
End Sub

So how does the tested code work then? The text box is going to be different all the time anyway its not predetermined. Plus what is that Left(txtbox.Text, 18) + Left(combo.Text, 2) etc?

LCS
01-20-2006, 06:12 PM
Private Sub Combo1_Change()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Replace "1" with the word in the combo box and "2" to the text you want to appear in the text box.

TheSpectator
01-20-2006, 06:31 PM
Private Sub Combo1_Change()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Replace "1" with the word in the combo box and "2" to the text you want to appear in the text box.

It semi-works

1) If I manually type in one of the combobox selections it will write the text. If I select it from the combobox it won't.

2) It replaces EVERYTHING there, I only need certain ones to change.

For example if I tried

"00000000000000000000000000000000000000000000000000"

and typed in "lol" it would change to

"lol"

not

"lol00000000000000000000000000000000000000000000000"

EDIT: I changed the Combo1_Change to Click and it works now but it still replaces all current text. So now I just need to know how to write to certain letters instead of overwritting.

LCS
01-20-2006, 06:34 PM
Private Sub Combo1_Change()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Private Sub Combo1_Click()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Try that.

TheSpectator
01-20-2006, 06:39 PM
Private Sub Combo1_Change()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Private Sub Combo1_Click()
If Combo1.Text = "1" Then Text1.Text = "2"
End Sub
Try that.

lol ya I just posted that Click worked I forgot bout that. But now I need it to overwrite just certain spots instead of removing previous text and putting just "2" from your example.

Dyndrilliac
01-20-2006, 07:50 PM
The API that are declared in "string.h" will work in VB when properly declared.

Ganondorf
01-21-2006, 09:19 AM
Isn't there a substring parameter... like TextBox1.Substring(1) = "whatever" or something like that. (That code will not work at all :P)

K? Pŕo?ćtiόnŹ
01-21-2006, 11:07 AM
Oh my ****ing god. Learn how to use VB if you're going to make something with it.


Private Sub combo_Click()
txtbox.Text = "------------------------------------------------------------"
txtbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
End Sub
change to


Private Sub combo_Click()
txtbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
End Sub
Was it that ****ing hard?

TheSpectator
01-21-2006, 12:12 PM
Dan']Oh my ****ing god. Learn how to use VB if you're going to make something with it.
Private Sub combo_Click()
txtbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
End Sub[/code]
Was it that ****ing hard?

Yes it was just that hard seeing how I could not interpret your poor knowledge of VB to of something proper.

A) There is no If statement for calling the routine for example



If ComboBox.Text = "Option 1" Then


B) Left/Right/Mid functions use strings so you'd need to classify txtbox.Text as a string



Dim sTemp As String

sTemp = txtbox.Text


C) You improperly used the Left/Right/Mid functions anyway which would **** up

D) You have nothing writing to the textbox... example



textbox.Text = Left$(sTemp, 3) & "r" & Mid$(sTemp, 5, 11)


E) It is a bad habit of using + (which will only work in some situations anyway) instead use &'s

TheUnknown
01-21-2006, 12:24 PM
... u guys r weirdin me out man, u still need help or no?

Mr_Mooo_Cow
01-21-2006, 10:16 PM
Yes it was just that hard seeing how I could not interpret your poor knowledge of VB to of something proper.

A) There is no If statement for calling the routine for example



If ComboBox.Text = "Option 1" Then


B) Left/Right/Mid functions use strings so you'd need to classify txtbox.Text as a string



Dim sTemp As String

sTemp = txtbox.Text


C) You improperly used the Left/Right/Mid functions anyway which would **** up

D) You have nothing writing to the textbox... example



textbox.Text = Left$(sTemp, 3) & "r" & Mid$(sTemp, 5, 11)


E) It is a bad habit of using + (which will only work in some situations anyway) instead use &'s
mmkay... lets start with...
A) Are you a monkey? must he do it for you ;)
B) Lies. If you are going to do that lets define numbers as numeric valued variables!! YES! </sarcasm>
C) More lies. (even if true fix it yourself you think-for-yourselfer
D) textbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
E) Next time lets just replace the +s with &s ourselves!!

TheSpectator
01-22-2006, 10:40 PM
mmkay... lets start with...
A) Are you a monkey? must he do it for you ;)
B) Lies. If you are going to do that lets define numbers as numeric valued variables!! YES! </sarcasm>
C) More lies. (even if true fix it yourself you think-for-yourselfer
D) textbox.Text = Left(txtbox.Text, 18) + Left(combo.Text, 2) + Mid(txtbox.Text, 21, 1) + Right(combo.Text, 1) + Mid$(txtbox.Text, 22)
E) Next time lets just replace the +s with &s ourselves!!

A) I was merely pointing out his flawed code
B) Sure if it is going to be the same value each time, but for what I need i won't work PLUS it is another good practice using strings: Left(string, length)
C) Oh it is true, you should only really use the Left$ function once if even then.
D) Partially falls under C) and partially I did not see the combo.Text, which is what you should have made bold. Again this isn't what I needed which writes letters FROM the combobox I need it to write different letters.
E) Same as A)
F) My bitchin proper code:



Private Sub ComboHero_Click()
Dim sTemp As String

If ComboHero.Text = "Goku" Then
sTemp = TextSC.Text
TextSC.Text = Left$(sTemp, 3) & "r" & Mid$(sTemp, 5, 11) & "e" & "n" & Mid$(sTemp, 18, 3) & "o" & Mid$(sTemp, 22, 15) & "y" & Mid$(sTemp, 38, 13)
End If
End Sub


Yes it is Dragonball Z, I basically made a save code generator for a map on Warcraft III the reason why I did it was mostly just because 1) fun map 2) gain more knowledge in vb 3) decoding it (the encryption). My friend wanted it as well.