|
Member 10728667 wrote: it doesn't list the races/results in order
You are going to explain what it is that you mean. Of course it lists them in order. It would really help us if you gave some idea of the input that you used, the output that you got and why the output is not what you expected it to be. Quite frankly without knowing what it is that you are trying to do here, it's really hard to figure out. But I can tell you that your code is doing exactly what you told it to do.
|
|
|
|
|
I have taken a quick look:
1. change those
Console.ReadLine()
after every Next's to
Console.WriteLine()
2. There is a logical error here, find and fix it yourself:
For index = 0 To 7
If (chevy(index) < ford(index)) Then
chevyCount = chevyCount + 1
Console.WriteLine("Chevy won by " & ford(index) - chevy(index) & " . ")
Console.WriteLine("Chevy has won " & chevyCount & " races.")
End If
Next
3. You have missed out one more condition in:
If chevyCount > fordCount Then
Console.WriteLine("Chevy wins the match!")
Else
Console.WriteLine("Ford wins the match!")
End If discover and add it yourself.
|
|
|
|
|
I am a high school student taking an online Computer Programming class. Using Visual Basic 2010 ver 4, I have to create a form with 2 text boxes and 2 buttons. 1 button will swap the text in the boxes and the other will close the form. I have the "close the form" button but I simply can not figure out how to code the swap button. Can anyone please help?
Thank you so much for your help.
Chase
|
|
|
|
|
Well it's not a big secret.
Declare a string variable
Assign the first text box text to your string variable
Assign the content of the first text box to the text of the second text box.
Assign the second text box text to the value that you stored in your string variable.
You should be able to figure it out. Give it a try.
modified 12-Apr-14 19:58pm.
|
|
|
|
|
1. Thank you for being honest about why you need help.
2. Basic concept is:
when swap button pushed
save text of 'A' box in local variable
set 'A' box text to contents of 'B'
set 'B' to value in local variable
If you need further help, post the code you are using.
Tim
|
|
|
|
|
Thank you for responding. This is my code:
Dim A As Char
A = TextBox1.Text
TextBox1.Text = TextBox2.Text
TextBox2.Text = String.Format("{A}", TextBox2.Text)
When I try to debug and enter in values it tells me "FormatException was unhandled."
Thank you again for your help. I don't know why I can't understand how to do this.
Chase
|
|
|
|
|
The variable A should be a string type. Also your String.Format statement is incorrect, but also unnecessary. Try
Dim tempStr As String
tempStr = TextBox1.Text
TextBox1.Text = TextBox2.Text
TextBox2.Text = tempStr
|
|
|
|
|
This might be a little late but still good for educational value.
All the suggestions are perfectly correct and easy to read when inspecting the code.
However there is one other way of doing this without declaring any additional variables like:
Dim txtA as string
Dim txtB as string
Each control has a "Tag" property that you can use to store any type of text.
Therefore you can write the following code without declaring any additional variables.
In your "Form_Load"
txtA.Tag = txtA.text
txtB.Tag = txtB.text
In the Button_Click event of the Swop Button you write:
txtA.text = txtB.Tag
txtB.text = txtB.Tag
The "Tag" property has many uses, this is but one possible use to keep from declaring too many variables for silly little tasks while you have other places to store relevant data.
Regard,
Tino
"Plan your work, Work your plan"
|
|
|
|
|
Imports System.IO
Imports System.IO.File
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim table As New DataTable
table.Columns.Add("ZipCode")
table.Columns.Add("State")
table.Columns.Add("City")
Dim parser As New FileIO.TextFieldParser("C//:test.csv") >>>>>>>> the program is running i can import test.csv file but in c: drive i want any .csv file import to the program ("c://*.csv) command is not runnig. pls help can u give me an example??
parser.Delimiters = New String() {";"}
parser.HasFieldsEnclosedInQuotes = True
parser.TrimWhiteSpace = True
parser.ReadLine()
Do Until parser.EndOfData = True
table.Rows.Add(parser.ReadFields())
Loop
Dim Sql As String = "INSERT INTO tblZipCode (ZipCode,State,City) VALUES (@ZipCode,@State,@City)"
Dim SqlconnectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=srkn;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;"
Using connection As New SqlClient.SqlConnection(SqlconnectionString)
Dim cmd As New SqlClient.SqlCommand(Sql, connection) ' create command objects and add parameters
With cmd.Parameters
.Add("@ZipCode", SqlDbType.VarChar, 15, "ZipCode")
.Add("@State", SqlDbType.VarChar, 20, "State")
.Add("@City", SqlDbType.VarChar, 30, "City")
End With
Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd
'--Update the original SQL table from the datatable
Dim iRowsInserted As Int32 = _
adapter.Update(table)
End Using
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
|
|
|
|
|
sensizbenlik wrote: can u give me an example
If you had gone and looked at the DirectoryInfo Class[^] just like you was told to here[^] you would have found the DirectoryInfo.GetFiles[^] method that provides you an example for what you want to do.
|
|
|
|
|
Do some research, you have been given the pointers to where to look. No one is going to write your code for you...
Here is some pseudo code. Split the parsing code into a new method.
get the directory info
for each of the fileinfo in the directoryinfo
pass the fileinfo to the parsing function.
Now go write your code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
Dim parser As New FileIO.TextFieldParser("c://test.csv")
i can import a csv file like this code
but
i want to import all csv files in c: driver to database
Dim parser As New FileIO.TextFieldParser("c://*.csv")is not working
pls help
|
|
|
|
|
|
thanks for replying i look the web site but icant do . .
i have a project. a machine system always reports in csv file to c: folder.but every time it reports different csv file .so i have to take from c: all csv files that s my code
Imports System.IO
Imports System.IO.File
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim table As New DataTable
table.Columns.Add("ZipCode")
table.Columns.Add("State")
table.Columns.Add("City")
Dim parser As New FileIO.TextFieldParser("C//:test.csv") (in here i want from visualbasic that it has to search csv files in c: and paste into to program)
parser.Delimiters = New String() {";"}
parser.HasFieldsEnclosedInQuotes = True
parser.TrimWhiteSpace = True
parser.ReadLine()
Do Until parser.EndOfData = True
table.Rows.Add(parser.ReadFields())
Loop
Dim Sql As String = "INSERT INTO tblZipCode (ZipCode,State,City) VALUES (@ZipCode,@State,@City)"
Dim SqlconnectionString As String = "Data Source=(localdb)\Projects;Initial Catalog=srkn;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;"
Using connection As New SqlClient.SqlConnection(SqlconnectionString)
Dim cmd As New SqlClient.SqlCommand(Sql, connection) ' create command objects and add parameters
With cmd.Parameters
.Add("@ZipCode", SqlDbType.VarChar, 15, "ZipCode")
.Add("@State", SqlDbType.VarChar, 20, "State")
.Add("@City", SqlDbType.VarChar, 30, "City")
End With
Dim adapter As New SqlClient.SqlDataAdapter()
adapter.InsertCommand = cmd
'--Update the original SQL table from the datatable
Dim iRowsInserted As Int32 = _
adapter.Update(table)
End Using
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
|
|
|
|
|
You have worked out how to loop through the parsed data now apply that to the directory's files. User System.IO.DirectoryInfo and get all the files in the folder and put this (and the rest of the processing) insode that loop.
sensizbenlik wrote: Dim parser As New FileIO.TextFieldParser("C//:test.csv") (in here i want from visualbasic that it has to search csv files in c: and paste into to program)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
pls give an example on my code via User System.IO.DirectoryInfo.
|
|
|
|
|
|
Hello Guys,
I need to logout user while closing all open forms and reopen the login form.
I did the following:
(Main Form)
Private Sub btnLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogout.Click
LoginForm.Close()
LoginForm.Dispose()
LoginForm = Nothing
ModuleLoad.LoginForm_Load()
End Sub
(Login Form)
Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Close all the forms but Login form
For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
If My.Application.OpenForms.Item(i) IsNot Me Then
My.Application.OpenForms.Item(i).Close()
End If
Next i
Exit sub
---------------------------------------------------------------
I get an error on ModuleLoad.LoginForm_Load() stating LoginForm_Load() is not a member of System.ModuleHandle..
I tried a number of declarations , no luck..
Guy me on this one.
Thanks
|
|
|
|
|
What code is executed in the ModuleLoad? And can you show us how the Program-entry point?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for reply,
That is my problem..
I have put this code:
<ComVisibleAttribute(True)>
Public Structure ModuleHandle
Share Sub LoginForm_Load()
End Sub
End Structure
--------
I want the loginForm to reload so the user can login
Thanks again
|
|
|
|
|
waner michaud wrote: I want the loginForm to reload so the user can login If the main-form closes, (as in, "all forms"), the application closes.
That raises another problem; how does one close your application? By closing the loginform? If yes, then the login-form would be the mainform, hidden when someone logs in, closes if someone cancels the login.
Alternatively, you can control the exit of the application by adding an explicit entry point (or does the IDE generate one nowadays?) Add a module like below;
Module Module1
Sub Main()
Using loginForm As New LoginForm()
While loginForm.ShowDialog() <> DialogResult.Cancel
Using mainForm As New MainForm()
MainForm.ShowDialog()
End Using
End While
End Using
End Sub
End Module Next, open the projects' properties (right click in solution explorer, or using the main menu), go to tab "Application" and play a bit with the "Shutdown mode" setting. Uncheck "Enable application framework", and change the "Startup object" (on the same tab, was called "Startup form" before the uncheck) to "Module1".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello again,
Thanks for your response.
I have an exit button that closes the application completely. But what I want is to log out button that will log out the current user and allow a new user to log in.
Basically that's what I want to accomplish.
Thanks again
|
|
|
|
|
That's what the example does, albeit you'll need to modify your own app.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello all i am new to this language and i have ported my code from vb6 to vb.net and getting this issue.
I am getting the error in this code line=
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
I dont understand how to fix this issue ,i am helpless
Any one here please help me i will be thankful to you
<pre> Public Function fnInitializeTimer() As Object
Dim strTemp As String
'we need unique name for timer hence appended the number of control to the name
'UPGRADE_WARNING: Controls method Controls.Count has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
strTemp = "Timer" & frmMain.Controls.Count() + 1
'Initialize the timer variable
'UPGRADE_ISSUE: Controls method Controls.Add was not upgraded. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
'mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer = frmMain.Controls.Add("VB.Timer", strTemp)
mvarTimer.Enabled = False
End Function
|
|
|
|
|