|
OK....so im trying to get a code for a button....so when i click the button it will bring up files that you can load a text file into a listbox.....any help?.....im on visual basic 8 and its different than vb6 so plz help with vb8 only
|
| __M4D_M0F0__ Sunday, March 22, 2009 9:01 PM |
Hi __M4D_M0F0__,
The code Dim text As String = File.ReadAllText(fileName) get the text from the file you have selected, set it to the Text property of TextBox will be ok.
| ImportsSystem.IO |
|
| PublicClassForm1 |
|
| PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click |
| DimopenfileDlgAsOpenFileDialog=NewOpenFileDialog() |
| openfileDlg.Filter="TextFile|*.txt" |
| IfopenfileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=openfileDlg.FileName |
| DimtextAsString=File.ReadAllText(fileName) |
| Me.TextBox1.Text=text |
| EndIf |
| EndSub |
| EndClass |
Do you have any question about it?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Wednesday, March 25, 2009 2:07 AM |
Hi M4D_MOFO,
The Text property of ListBox is not like TextBox.Text. It represent the text of the currently selected item in the control.
If you want to show multi-line in a TextBox, you can set Multiline property of TextBox to True. And set ScrollBars.Vertical to the ScrollBar property. It can load all text and show scrollbar when necessary.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Thursday, March 26, 2009 2:34 AM |
Hi __M4D_M0F0__,
To erase all text, you can set the Text property of TextBox to "". Like TextBox1.Text = "";
If you have any problem, feel free to come to MSDN. It's my duty to serve Microsoft customers.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:20 AM
-
|
| Kira Qian Friday, March 27, 2009 1:27 AM |
Hi __M4D_M0F0__,
Here is the whole sample including load and save.
| ImportsSystem.IO |
|
| PublicClassForm1 |
|
| PrivateSubbtnLoad_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnLoad.Click |
| DimopenfileDlgAsOpenFileDialog=NewOpenFileDialog() |
| openfileDlg.Filter="TextFile|*.txt" |
| IfopenfileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=openfileDlg.FileName |
| DimtextAsString=File.ReadAllText(fileName) |
| Me.TextBox1.Text=text |
| EndIf |
| EndSub |
|
| PrivateSubbtnSave_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnSave.Click |
| DimsaveFileDlgAsSaveFileDialog=NewSaveFileDialog() |
| saveFileDlg.Filter="TextFile|*.txt" |
| IfsaveFileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=saveFileDlg.FileName |
| File.WriteAllText(fileName,TextBox1.Text) |
| EndIf |
| EndSub |
| EndClass |
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Friday, March 27, 2009 3:42 AM |
Hi __M4D_M0F0__,
Here is the sample to let user choose a txt file to open and read all text from it.
| ImportsSystem.IO |
| PublicClassForm1 |
| PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click |
| DimopenfileDlgAsOpenFileDialog=NewOpenFileDialog() |
| openfileDlg.Filter="TextFile|*.txt" |
| IfopenfileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=openfileDlg.FileName |
| DimtextAsString=File.ReadAllText(fileName) |
| 'usethistexttofillyourListBox |
| EndIf |
| EndSub |
| EndClass |
|
After you get all text from that file, you can use it to fill your ListBox. Does this what you need? Please feel free to tell me if you need any help.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Tuesday, March 24, 2009 8:13 AM |
kk this is wht i need......but when i opened the folder and clicked a text file it didnt load into the textbox....any help??
|
| __M4D_M0F0__ Tuesday, March 24, 2009 7:18 PM |
Hi __M4D_M0F0__,
The code Dim text As String = File.ReadAllText(fileName) get the text from the file you have selected, set it to the Text property of TextBox will be ok.
| ImportsSystem.IO |
|
| PublicClassForm1 |
|
| PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click |
| DimopenfileDlgAsOpenFileDialog=NewOpenFileDialog() |
| openfileDlg.Filter="TextFile|*.txt" |
| IfopenfileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=openfileDlg.FileName |
| DimtextAsString=File.ReadAllText(fileName) |
| Me.TextBox1.Text=text |
| EndIf |
| EndSub |
| EndClass |
Do you have any question about it?
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Wednesday, March 25, 2009 2:07 AM |
kk i did it but it still wont load into a Listbox.......it opens up my folders and i select the text file i want and it does nothing.....none of the text shows up in the ListBox....is there another part of the code tht i need to use to tell it to load the text file into listbox1 |
| __M4D_M0F0__ Wednesday, March 25, 2009 10:23 PM |
Hi M4D_MOFO, Please download the whole sample here, I made it in VS 2008 http://cid-380a93ce0876cf8b.skydrive.live.com/self.aspx/Microsoft MSDN Work/Solution Code/VB|_LoadFile.rarIt's a TextBox. Why do you need a ListBox? The second post you said load into a TextBox. Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Thursday, March 26, 2009 1:48 AM |
The code works on a text box.....but wht i want is it to load into a list box so like if you have multy lines of text it will have it in the list box.....like one thing per line.....a text box shows one line and you cant scroll up and down....i want them to load in listbox so i can scroll up and down....wht changes i need to do for the listbox???
|
| __M4D_M0F0__ Thursday, March 26, 2009 2:24 AM |
Hi M4D_MOFO,
The Text property of ListBox is not like TextBox.Text. It represent the text of the currently selected item in the control.
If you want to show multi-line in a TextBox, you can set Multiline property of TextBox to True. And set ScrollBars.Vertical to the ScrollBar property. It can load all text and show scrollbar when necessary.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Thursday, March 26, 2009 2:34 AM |
ty so much for your time......sry for the hassle....now if you dont mind...i know ive been bugging....but is there a quick simple code to erase the info out of textbox....like another button code just to clear it out of textbox?? |
| __M4D_M0F0__ Thursday, March 26, 2009 7:42 PM |
Hi __M4D_M0F0__,
To erase all text, you can set the Text property of TextBox to "". Like TextBox1.Text = "";
If you have any problem, feel free to come to MSDN. It's my duty to serve Microsoft customers.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:20 AM
-
|
| Kira Qian Friday, March 27, 2009 1:27 AM |
kk....thank you for all your help....i really appreciate this.....i couldnt find anyone who knew vb8 everybody knows vb6....but you have been a big help....now all i think i have to do is do a save button and ill be finish i already got the savedialog thing and all....just got to code it but you have really helped out....whenever you get a chance i need help with the save button were it will save but i have in textbox as a text file.....but whenever you get a chance....ty |
| __M4D_M0F0__ Friday, March 27, 2009 3:30 AM |
Hi __M4D_M0F0__,
Here is the whole sample including load and save.
| ImportsSystem.IO |
|
| PublicClassForm1 |
|
| PrivateSubbtnLoad_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnLoad.Click |
| DimopenfileDlgAsOpenFileDialog=NewOpenFileDialog() |
| openfileDlg.Filter="TextFile|*.txt" |
| IfopenfileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=openfileDlg.FileName |
| DimtextAsString=File.ReadAllText(fileName) |
| Me.TextBox1.Text=text |
| EndIf |
| EndSub |
|
| PrivateSubbtnSave_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnSave.Click |
| DimsaveFileDlgAsSaveFileDialog=NewSaveFileDialog() |
| saveFileDlg.Filter="TextFile|*.txt" |
| IfsaveFileDlg.ShowDialog()=Windows.Forms.DialogResult.OKThen |
| DimfileNameAsString=saveFileDlg.FileName |
| File.WriteAllText(fileName,TextBox1.Text) |
| EndIf |
| EndSub |
| EndClass |
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer byKira QianMSFT, ModeratorFriday, March 27, 2009 6:19 AM
-
|
| Kira Qian Friday, March 27, 2009 3:42 AM |
ty so much....if i need something else i know who to come to :) |
| __M4D_M0F0__ Saturday, March 28, 2009 2:34 AM |