Question text from textbox by name?

drumminfreak

Member
Joined
Oct 31, 2011
Messages
5
Programming Experience
Beginner
Hello to you all.

Ok, ive had a brief look round and can't find the answer to this question. I've also been browsing the internet for what feels like a life time in order to find this answer but i've had no success so far and its driving me up the wall.

What i'm doing is a very simple (or so i thought) project for my local Pool Team. I haven't had much experience in VB apart from very basic VBA so treat me like a complete newbie :p

Ok, the bit im struggling with is: I'm trying to make text files for each player. With the text file being called Player 1, player 2 etc etc, and the first line inside the txt file to be their name., I'm getting the "player 1", "Player 2" part, but the first line is constantly coming up with "textbx_1" instead of whats inside the Text box.

Here's the code i have; hopefully it might show my mistake. Any help would be greatly greatly appreciated.

(the focusedtextbx is something i did recently (as i would also like it to see inside the text box and not keep the string.) i would like to keep my script small.) )

PrivateSub btn_okpoints_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_okpoints.Click
Dim intcount AsInteger
Dim text_filename AsString
Dim focusedtextbx AsString
Dim firstlinetext AsString
intcount = 0
If intcount = "0"ThenGoTo actualsums
 
actualsums:
intcount = intcount + 1
focusedtextbx =
"txtbx_name" & intcount.ToString
If focusedtextbx = ""ThenGoTo exitme ElseGoTo txtfile_name

txtfile_name:
text_filename =
"C:\POOL_LEAGUE_DATA\player" & intcount & ".txt"
firstlinetext = "textbx" & intcount.ToString

Dim
objWriter AsNew System.IO.StreamWriter(text_filename, True)
objWriter.Write(firstlinetext)
objWriter.Close()
If intcount = "18"ThenGoTo exitme ElseGoTo actualsums
 
 
exitme:
If MsgBox("Text written to file", MsgBoxStyle.OkOnly) = MsgBoxResult.Ok ThenExit Sub
EndSub


Thank you for your time. And Thank you so much for any help you can give me. (sorry if this is posted in the wrong place too. :p)

Regards

Drumminfreak
 
Ok i've looked that up.

CType(
Me.Controls(ename), PictureBox).Image = path

I'm going to sound like a complete cretin, but i am learning but how would i write it in my script
(i'm so sorry i really do feel like a newbie here!)
 
The line:
firstlinetext = "textbx" & intcount.ToString

is I assume the first line of text you want to be in your text file... but look at what you're doing, you're using the string literal "textbx" and concatenating it with the string representation of an integer value... you will always get something like "textbx1", "textbx2", "textbx3" etc from that.

It seems like the code is doing exactly what you are telling it to do, but you are not telling it to do what you actually want it to do.

It seems like you want firstlinetext to be set to the players name... not to a string constant and a number. I can't help you beyond that because I don't even see any player names or variables that might store players names in the code you posted.

To get the content of a text box you access its Text property. So if you had a textbox named TextBox1 you can get it's string contents with TextBox1.Text
 
Aside from the problem you specifically asked about the code you posted is a mess...

The first few lines of the function:
intcount = 0
If intcount = "0"ThenGoTo actualsums
actualsums:


Do nothing... you set a variable to zero and then immediately check to see if it's zero... it will always be, because you just set it, the check is redundant. Then, you use a goto to go to the very next line... that is also redundant, you don't need to tell the code to go to the next line it does that automatically... there's more but I'm out of time at the moment.
 
Back
Top