Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello, I have a problem in the classifications of my texts in streamwriter in visual basic.


How to do this?

Thank you!

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 26-Mar-11 8:42am
v3

1 solution

Easy: you just need to change one line:
VB
textfilestream.WriteLine(Product & " " & Size & " " & Cost)

becomes:
VB
textfilestream.WriteLine("Product: " & Product & " Size: " & Size & " Cost: " & Cost)


Or there is the advanced version:
VB
extfilestream.WriteLine("Product: {0} Size: {1} Cost : {2}", Product, Size, Cost)
This make look complicated, but all it is saying is "Where I have a pair of curly brackets, replace this with a value from the list at the end". So "{0}" is replaced with the first parameter, "{1}" by the second and so on. Later, you will learn how to use this to change how numbers and so on are displayed. It's simple when you get used to it!

[edit]Format string version add - OriginalGriff[/edit]



"Well I have a combobox with 3 items namely: Product Size and Cost.

I have also a maskedtextbox.

If I select "Product" and "Size" on the combobox, I want to disable the maskedtextbox from filling, how must I do it?"


That's more complicated, and I'm not sure you have enough background for it yet.
So if this is gobble-de-gook to you, I'm not explaining it! It can wait until you reach it in your course.

1) Handle the SelectionChanged event for the ComboBox.
2) In the handler, if the selection is "Product and Size" then set the MaskedTextBox.Enabled property to false.
3) Otherwise, set it to true.

You will probably need to set the property correctly in your Form.Load event as weell to ensure it is OK before teh user clicks anything.
 
Share this answer
 
v3
Comments
Yusuf 20-Mar-11 11:30am    
+5 for mentioning the right way
555336 20-Mar-11 12:13pm    
THANK YOU IT WORKS. Can you help me in a last problem?
OriginalGriff 20-Mar-11 12:18pm    
You are welcome!
What's the "last problem"?
555336 20-Mar-11 12:27pm    
Well I have a combobox with 3 items namely: Product Size and Cost.

I have also a maskedtextbox.

If I select "Product" and "Size" on the combobox, I want to disable the maskedtextbox from filling, how must I do it?
OriginalGriff 20-Mar-11 12:41pm    
Answer updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900