|
Hi All:
I would like to share data between two Windows forms in this manner:
- Form 1 browses for the name of a text file, stores the name in a string variable (strTextFile), and calls Form 2 with the Form2.Show() command
- Form 2 has one button to display this text file in a text window called txtDocument.Text using My.Computer.FileSystem.ReadAllText(strTextFile), and two others to do Printer Setup and Print, respectively
My question is: how do I pass the name of the text file from Form 1 to Form 2? I am new to VB.NET, so please bear with me.
Thanks.
DERECK R. PRINCE
President
Roraima Technologies, Inc.
"Customizing Technology for ALL Your Business Needs!"
Saint Louis, Missouri, USA
Phone: 1-314-569-9035
|
|
|
|
|
roraima wrote:
My question is: how do I pass the name of the text file from Form 1 to Form 2? I am new to VB.NET, so please bear with me.
The most obvious way, if Form2 can do nothing without this string, is for Form2 to take a string in it's constructor, so you can't create a Form2 instance without passing this string in. Otherwise, you can make the string a property on Form2, and pass it in before calling Show().
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Whoa!!! Thanks for that, Christian, but I am afraid you are a little over my head with that reply! How about a code sample to illustrate what you mean?
And sorry for the bother; I am new at this.
DERECK R. PRINCE
President
Roraima Technologies, Inc.
"Customizing Technology for ALL Your Business Needs!"
Saint Louis, Missouri, USA
Phone: 1-314-569-9035
|
|
|
|
|
OK - I'll try. I really don't use VB.NET, I kind of think it sucks
Public Class Class1
' A private variable to store the string
Private _path As String
' This is apparently how you add a constructor to VB.NET
Public Sub New(ByVal path As String)
Me._path = path
' You probably don't need to store the string, you could just read the file, and store it's contents.
End Sub
Private Sub New()
End Sub
End Class
That's from a project I just whipped up - the constructor is the method that is called when you create a new object. So when you create a new Class1, in this instance, you need to pass it a string. However, the default constructor ( which takes no arguments and does nothing ) is still available, so I define it to be private ( which means no-one can call it, forcing the one that takes the string to be called ). Once you have the string, you can use it to read the file whenever you like. I am sort of anticipating that question, the link below is to an article on reading text files in VB.NET.
http://www.freevbcode.com/ShowCode.asp?ID=4492[^]
The other way is to have a property, like this:
Public WriteOnly Property Path()
Set(ByVal Value)
_path = Value
' You would also read the text file here, probably
End Set
End Property
Now, you can do myForm.Path = "thepath" before calling the Show method.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks, Christian. I'll go try this and see how I go.
DERECK R. PRINCE
President
Roraima Technologies, Inc.
"Customizing Technology for ALL Your Business Needs!"
Saint Louis, Missouri, USA
Phone: 1-314-569-9035
|
|
|
|
|
Hello!
I have another, perhaps more simpler solution to this question of sharing data between two forms...
First declare a public (global) variable in form 2......
Public Str as String <---
now create an object of form 2 in form 1
Like......
Dim Frm2 as new Form2
Frm2.Str.Text=strTextFile.Text
Frm2.Show()
now the value of strTextFile would be in str and you can access it in you function....
_mubashir
|
|
|
|
|
You have another way to accomplish what you are asking for
As a Form it´s a class itself you can create a property (a method) that GETS o RETURNS any variable you need... for example
<br />
'In this case, the form is called Calculator, this is "form2"<br />
Public Class Calculator<br />
Inherits System.Windows.Forms.Form<br />
<br />
Dim _myTextBox As TextBox<br />
<br />
Public Property GetSetTextBox() As TextBox<br />
Get<br />
Return Me._myTextBox<br />
End Get<br />
Set(ByVal Value As TextBox)<br />
Me._myTextBox = Value<br />
End Set<br />
End Property<br />
<br />
'... the rest of the code<br />
And From form1 (the form who calls the second one)
<br />
Dim Form2 as New Form2<br />
Form2.GetSetTextBox = TextBox1 'Any textbox in the form<br />
In this way you can return a variable or a reference to a full control, have fun
PD: Sorry about my english... is not very good
|
|
|
|
|
My suggestion is to have a shared variable between the 2 forms. That way, if you modify the variable from one form, it keeps the value of the variable when you access it from form2.
So for example:
you can specify a variable str in form1 this way
Public Class Form1
Public shared str as string
...
end class
you can access the variable form either form1 or form2.
to modify it form form1, simply use this way
str = txtDocument.text
to access or modify from form2, use this way
form1.str = "Another Text"
or you can also use it in you textbox.
My.Computer.FileSystem.ReadAllText(Form1.str)
Hope this helps
Good luck
|
|
|
|
|
Hi All:
Thank you all for your patience in assisting me with this little project. The Property reply did the trick, and I am happily continuing on my VB programming way! You guys are the best!
DERECK R. PRINCE
President
Roraima Technologies, Inc.
"Customizing Technology for ALL Your Business Needs!"
Saint Louis, Missouri, USA
Phone: 1-314-569-9035
|
|
|
|
|
How to make Intelligent datagrid like yahoo messenger address tab. When we type any word first letter like
In Datagrid Column name is Name it has different name like
Muhammad Waqas Butt
Muhammad Sheraz Butt
Saad Butt
Aarij Butt
So when we type M then it show and select the record and then type u it show only record which are starting from M and second word u.
Any Idea? In C#.Net or VB.Net
|Muhamad Waqas Butt|
waqasb4all@yahoo.com
www.sktech.freewebspace.com
|
|
|
|
|
If you would have a textbox for each column where you enter the string which should be searched for, i would suggest you to use the textchanged event of that textboxes. you could go through each row of the dataset which is stores the information and check if the specific column contains the string which you're searching for and if it does, copy that row to a second dataset which is binded to the datagrid. although it would work, its a bad idea, since you would have to use two datagrids or something like this to store the original informations, and the ones which should be shown. you also would have to go through the whole table everytime someone writes something. thats not a problem if you're using a small datagrid, but if it gets larger, you will get performance problems...
just some suggestions because nobody answered yet, no good ones though :/
good luck,
mik
|
|
|
|
|
I am building a VB.Net Windows application. I would like to allow the user to click a button which will open their default mail client, insert the subject, body, and emaill addresses, and then attach one or more files. The user would then be able to change any of the information and send their their email client.
I've seen several posts that suggest using the "mailto:" command with ShellExecute seems to be the easiest wayto go, however this does not seem to support attachments. I've also seen several posts that suggest using MAPI to accomplish this, but those all seem to be VB6 (It doesn't seem to be available out of the box with VB.net).
There is also functionality that I could use for Outlook specifically, however I want to keep this fairly generic so that other email clients could be used as well.
I would greatly appreciate any suggestions.
|
|
|
|
|
I'm trying to figure out how to select an an item in in a listview at runtime
e.g. searching a listview (in detail view) for a specific item and highlighting it
I've tried:
listview.items(i).selected = true
where i is the index of the item i want to select - the item is added to the listviewselecteditems collection, but it does not highlight. Do I need to refresh the control after selecting it, or is some extra handling in the paint event needed?
Dave
|
|
|
|
|
Ha!
Just managed to answer my own question -
remember to add:
listview.items(i).selected = true
listview.select()
many thanks to Jason Heine for his article...
My new motto: think twice, speak once
Dave
|
|
|
|
|
Hi
I tried to get some printer-informations by using a wmi-query. It works fine until a printer goes offline. It takes very long to get those informations then.
What do i want it to do?
- It should be much faster to get the printer-informations (about 3 secs, no matter whether a printer is offline or not)
OR
- It should run the application.doevents() command at least every second. (to provide a progressbar which is worth to be called a PROGRESSbar
What did i already try to do?
- Optimize the WMI-Query (which was a bit successful at least)
- Set a seperate Timer which runs the application.doevents() command (for the possibility of a progressbar, which shows that the computer doesn't hang around)
The Query-optimization increased the speed by 1-2 seconds. but it still took too long to get the printer-informations.
The timer freezes if the specific line of code is executed (if all printers are online its about 3secs, if only one of the printers is offline, it takes up to 15 secs and more), so that's not the solution, too.
All together: very unsuccessful
I will show you some example code, so you may rebuild the problem, if you're interested in
Declaration/Definition of variables:
<br />
Private Printer As System.Management.ManagementObject<br />
Private PrinterSelect As New Management.SelectQuery("SELECT Name, PrinterStatus, DriverName, PortName, Comment, Local, Network, Default FROM Win32_Printer")<br />
Private PrinterSummary As New Management.ManagementObjectSearcher(PrinterSelect)<br />
Private PrinterCollection As Management.ManagementObjectCollection<br />
executing code:
<br />
PrinterCollection = PrinterSummary.Get()<br />
'Application.DoEvents()<br />
For Each Printer In PrinterCollection<br />
{...}<br />
Next Printer<br />
PrinterCollection = Nothing<br />
everytime the third line of executing code ("For Each Printer in PrinterCollection") being executed, the computer starts to hang.
please tell me, if you need more informations about the problem.
i would be thankful and pleased for every constructive response
so far,
mik
|
|
|
|
|
|
Great. It works fine. Now i'm able to make the progressbar be a real progressbar which shows continously progress thanks a lot, wouldn't have get that by myself.
here's some example code how it could look like:
declaretion/definition:
Private Printer As System.Management.ManagementObject
Private PrinterSelect As New Management.SelectQuery("SELECT Name, PrinterStatus, DriverName, PortName, Comment, Local, Network, Default FROM Win32_Printer")
Private PrinterSummary As New Management.ManagementObjectSearcher(PrinterSelect)
Private PrinterCollection As Management.ManagementObjectCollection
Private observer As New Management.ManagementOperationObserver
Private completionHandler As New WMICompletionHandler
executing code:
PrinterCollection = Nothing
PrinterSummary.Get(observer)
PrinterCollection = PrinterSummary.Get()
While Not (completionHandler.IsComplete)
Application.DoEvents()
System.Threading.Thread.Sleep(500)
End While
For Each Printer In PrinterCollection
{...}
next printer
... it redraws the progressbar while executing the wmi query, too.
you need to add the completionhandler class, shown on that msdn page.
thanks again
|
|
|
|
|
I wanna ask easier way for an T-SQL Clause
Imagine a table AS following
CODE - TYPE - TOTAL<br />
1132 IN 100<br />
1134 IN 140<br />
1134 OUT 230<br />
1135 IN 240<br />
1135 OUT 50<br />
1136 IN 70<br />
1137 OUT 110
I need a sqlclause it will group by code and calculate Total, u have to multply OUT type with -1
the final table what i need to get is
CODE - TOTAL<br />
1132 100<br />
1134 -90<br />
1135 190<br />
1136 70<br />
1137 -110
I assume The clause like that
select CODE,SUM(If (TYPE='OUT',TOTAL*-1, TOTAL) from DETAILS<br />
group by CODE,TYPE Order by CODE
But something is missing
-- modified at 9:24 Monday 5th September, 2005
|
|
|
|
|
The correct sentence is:
select CODE, TOTAL = SUM(case when TYPE = 'OUT' then TOTAL * -1 else TOTAL end) from DETAILS
group by CODE Order by CODE
Regards,
Vidal Gutiérrez Ch.
|
|
|
|
|
|
hcmuns wrote:
Could you tell me what books like Real World .NET Application book
You want other books like this one ? Why not go to amazon.com and see what else they recommend ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I want to rotate the label control.I have searched but i have only got the solution to rotate the text appear on the label. So if anybody could help me in this regard then it will be pleasure for me.
Thanks
Premanand Jha
|
|
|
|
|
Have a look at:
http://www.codeproject.com/useritems/Vertical_Label.asp
it may be of help.
Bye
Briga
|
|
|
|
|
Hi
I am getting a error "Specified argument was out of the range of valid values.Parameter name: '-2147483648' is not a valid value for 'index'." When I was trying to set selected value property value for the combo box.
I have given the code for your reference.
With cboName
.DataSource = dtSource
.DisplayMember = strDisplayMember
.ValueMember = strValueMember
End With
cboName.SelectedValue = intCalibrateId.ToString
After binding the combo box member, I am setting the value to the selectedValue property.
Please findout where I have done a mistake and how to rectify this.
Thanks in advance
M. Rabeek Ahamed
|
|
|
|
|
hmm
Try out by putting the Selectedvalue property int he With-EndWith block
like,
With cboName
.DataSource = dtSource
.DisplayMember = strDisplayMember
.ValueMember = strValueMember
.SelectedValue = intCalibrateId.ToString
End With
If this doesnt work than check out for the intCalibrateId value....
and try without casting it to string.
_mubashir
|
|
|
|
|