Answered by:
Module form

Question
-
I have two forms one a normal forum "form1" and a module form "module Ippa".
On my main form I have a button to click and then i must run the module form, but I cannot get it to run, how do you run a module form, I can get it to run my about form, but not the module Ippa form.
Wednesday, June 18, 2008 8:22 AM
Answers
-
When you use for each you are looping through a collection of items . Your code only puts the last item into the text box . For example if I use this code .
Code SnippetImports
System.Net.NetworkInformationPublic
Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim returnValue As NetworkInterface()
returnValue = NetworkInterface.GetAllNetworkInterfaces()
For Each RV As NetworkInterface In returnValue
TextBox1.AppendText(RV.Description & vbCrLf)
Next
End Class
I get this in textbox1
Code SnippetNVIDIA nForce Networking Controller - Packet Scheduler Miniport
MS TCP Loopback interfaceFriday, June 20, 2008 9:50 AM
All replies
-
Again, my ignorance is showing because I don't know what a "module form" is. Neither Google nor MSDN turned up anything useful on this phrase.
Please post the code you are using to create a "module form".
Wednesday, June 18, 2008 12:32 PM -
If Ippa is just a module you need to call the function in it that you want.Wednesday, June 18, 2008 1:38 PM
-
As you can see on screen one. Appi.vb is where the module is.
On screen two is some of the code. I want to know how can I call this code to used on my main form, I can not get it to run.
Thursday, June 19, 2008 7:46 AM -
Call the sub
Code SnippetPublic
Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
main()
End Sub
End Class
Code SnippetModule
Module1Sub main()
MessageBox.Show("Hello World", "Module messagebox")
End Sub
End Module
Thursday, June 19, 2008 8:56 AM -
I have done this, but when I run the program and click on the button nothing is happening.
Form1
Code SnippetPrivate Sub Toets1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Toets1.Click
Appi.vb
Code SnippetImports
SystemImports
System.Collections.GenericImports
System.TextImports
System.NetImports
System.Net.NetworkInformationModule
Ippa Sub Main()ShowNetworkInformation()
Console.ReadLine()
End Sub Public Sub ShowNetworkInformation() Dim ipProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()Console.WriteLine(
"Host name: {0}", ipProperties.HostName)Console.WriteLine(
"Domain name: {0}", ipProperties.DomainName) For Each networkCard As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()Console.WriteLine(
"Interface: {0}", networkCard.Id)Console.WriteLine(
"" & Chr(9) & " Name: {0}", networkCard.Name)Console.WriteLine(
"" & Chr(9) & " Description: {0}", networkCard.Description)Console.WriteLine(
"" & Chr(9) & " Status: {0}", networkCard.OperationalStatus)Console.WriteLine(
"" & Chr(9) & " MAC Address: {0}", networkCard.GetPhysicalAddress().ToString())Console.WriteLine(
"" & Chr(9) & " Gateway Address:") For Each gatewayAddr As GatewayIPAddressInformation In networkCard.GetIPProperties().GatewayAddressesConsole.WriteLine(
"" & Chr(9) & "" & Chr(9) & " Gateway entry: {0}", gatewayAddr.Address.ToString()) NextConsole.WriteLine(
"" & Chr(9) & " DNS Settings:") For Each address As IPAddress In networkCard.GetIPProperties().DnsAddressesConsole.WriteLine(
"" & Chr(9) & "" & Chr(9) & " DNS entry: {0}", address.ToString()) Next Next End SubEnd
ModuleThursday, June 19, 2008 9:29 AM -
It looks like you have taken this code from a console application but are trying to use it in a Windows Forms application where Console.WriteLine has little use.
If you look at the output window (Ctrl-Alt-O) you should see the output of the sub main.
If you want to use it in a Forms app then modify the code to write to a multi-line textbox or a label.
Thursday, June 19, 2008 10:14 AM -
Thank you Dave299
I am trying to change it I got diffrent text box for each one now (don't know yet how to put it in one multi line texbox)
It shows the first two Host and domain name, but when I try the 4 one it give me this error
Card name "MS TCP Loopback interface"
It has something to do with thsi code
TextBox3.Text = networkCard.Name
Thursday, June 19, 2008 11:36 AM -
Replace console.writeline with textbox3.appendtext( "Your text" & vbcrlf )
vbcrlf is a line feed so the next text added goes to next line .
Thursday, June 19, 2008 12:12 PM -
I don't get closer to what I watn to do, What am I doing wrong.
Here is the code and a screenshot of what I am getting
Code SnippetPublic
Class IPAdd Public defaultGateway As String Private Sub IPAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ipProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()TextBox1.Text = ipProperties.HostName
TextBox2.Text = ipProperties.DomainName
For Each networkCard As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces()TextBox3.Text = networkCard.Id
TextBox4.Text = networkCard.Name
TextBox5.Text = networkCard.Description
TextBox6.Text = networkCard.OperationalStatus
TextBox7.Text = networkCard.GetPhysicalAddress().ToString()
For Each gatewayAddr As GatewayIPAddressInformation In networkCard.GetIPProperties().GatewayAddressesTextBox8.Text = defaultGateway
Next For Each address As IPAddress In networkCard.GetIPProperties().DnsAddressesTextBox10.Text = address.ToString()
Next Next End SubFriday, June 20, 2008 8:02 AM -
When you use for each you are looping through a collection of items . Your code only puts the last item into the text box . For example if I use this code .
Code SnippetImports
System.Net.NetworkInformationPublic
Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim returnValue As NetworkInterface()
returnValue = NetworkInterface.GetAllNetworkInterfaces()
For Each RV As NetworkInterface In returnValue
TextBox1.AppendText(RV.Description & vbCrLf)
Next
End Class
I get this in textbox1
Code SnippetNVIDIA nForce Networking Controller - Packet Scheduler Miniport
MS TCP Loopback interfaceFriday, June 20, 2008 9:50 AM -
bdbodger
Thank you, I understrand it now.
Friday, June 20, 2008 11:20 AM