|
Test this code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' supposing we have a label and it has the text 00:00:00 when the form loads
' Timer interval we can set as per requirement
' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100
s = Label1.Text.Split(":")
If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then
s(2) = Format(CInt(s(2)) + 1, "00")
ElseIf CInt(s(2)) = 9 Then
s(2) = Format(0, "00")
s(1) = CInt(s(1)) + 1
s(1) = Format(CInt(s(1)), "00")
End If
If CInt(s(1)) = 10 Then
s(0) = Format(CInt(s(0)) + 1, "00")
s(1) = Format(0, "00")
End If
Label1.Text = s(0) & ":" & s(1) & ":" & s(2)
End Sub
Hope this solves the purpose.
|
|
|
|
|
LOL!
This is awesome advice!!!
|
|
|
|
|
I just forgot to mention one thing.
Declare an string array globally like:
Dim s() as String
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' supposing we have a label and it has the text 00:00:00 when the form loads
' Timer interval we can set as per requirement
' I have set it for 0-9. If you want to test upto 1 minute then change 9 by 99 and 10 by 100
s = Label1.Text.Split(":")
If CInt(s(2)) >= 0 AndAlso CInt(s(2)) < 9 Then
s(2) = Format(CInt(s(2)) + 1, "00")
ElseIf CInt(s(2)) = 9 Then
s(2) = Format(0, "00")
s(1) = CInt(s(1)) + 1
s(1) = Format(CInt(s(1)), "00")
End If
If CInt(s(1)) = 10 Then
s(0) = Format(CInt(s(0)) + 1, "00")
s(1) = Format(0, "00")
End If
Label1.Text = s(0) & ":" & s(1) & ":" & s(2)
End Sub
Hope this solves the purpose.
|
|
|
|
|
Wow, this is pretty bad. A value of time like this would normally be represented in your code by a TimeSpan object. You can then increment this time by adding 1 second to it on each tick of a 1000 millisecond timer.
Your code can then be replaced by a very simple, single line of code:
Label1.Text = myTimeSpan.ToString()
|
|
|
|
|
Dave Kreskowiak wrote: Wow, this is pretty bad
Masterful understatement, such restraint.
|
|
|
|
|
Hi, i'm from mexico, sorry for my english...
i need help....
Somebody tell me how rotate my WinForm 360º or
rotate 3D my WinForm....
I Know that is very difficult.....
any link, document is good !!!
Thanks!!!!!!!
|
|
|
|
|
You can't. Instead, write your app using WPF.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hi i am new in vb.net and i am working on my assigment, I have crated ms access database, i can add new questions and i can also get all questions from database with 4 options it's working fine but now i want to randomize it
and code is some thing like this to open con. and display it and i also try to create array because we dont know how many questions are there in database so when con. opens first it counts how many questions are there and if array is smaller then it increse array size i am not sure that this right or wrong but i am just trying it and when i debug it it increses the array size if it small but i dont know how to randomize it
Try<br />
<br />
Me.conTest.ConnectionString = _<br />
"Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= MyTest.mdb"<br />
Catch eConnection As System.Exception<br />
MessageBox.Show(eConnection.Message)<br />
End Try<br />
<br />
'if array size is smaller then increase as per entry<br />
ArraySize = Count<br />
Dim IntegerArray(ArraySize) As Integer<br />
'sort integers<br />
Call SortArray(ArraySize, IntegerArray)<br />
Try<br />
odaTest.Fill(dsTest)<br />
'lblNo.Text = Me.BindingContext(dsTest.MyTest).Position<br />
Catch eLoad As System.Exception<br />
MessageBox.Show(eLoad.Message)<br />
End Try<br />
Call dsContacts_PositionChanged()<br />
End If
this is for array
Private Sub SortArray(ByVal N As Integer, ByVal SortedArray() As Integer)<br />
'increase the array size according to number of entry <br />
For I As Integer = 0 To N<br />
SortedArray(I) = I<br />
Next I<br />
End Sub
so can you please help me with this
waiting for your kind rep.
thanks
|
|
|
|
|
your questions should have an id in the database, use the Random.Next method to generate a random Id. If you need to make a series of questions with no repeats, build a list of array indexes and use the Random class to generate a random index into that array. Pull out the number at that index and remove it so it doesn't get used again
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hello sir
thanks for your rep.
this is what i have done, it's randomize the questions but i dont know how to stop displaying same question again
any help sir
Private Sub NavNext()<br />
Try<br />
odaTest.Fill(dsTest)<br />
R = Rnd() * ArraySize<br />
'[Go to the next entry]<br />
<br />
Me.BindingContext(dsTest, "MyTest").Position = R<br />
Catch eLoad As System.Exception<br />
MessageBox.Show(eLoad.Message)<br />
End Try<br />
'[See custom procedures]<br />
Me.dsContacts_PositionChanged()<br />
End Sub
I dont know that this is the right way to do it but i am trying
waiting for your kind rep.
|
|
|
|
|
Here is a basic code snipet of how to use an ArrayList to keep track of your random numbers.
My application is just one form with 2 buttons and a rich text box.
Click on button1 to generate a random number, it checks if it has not been generated before, adds it to the list and displays it in the textbox. If the number already exists, a msgbox is displayed.
Button2 is used to display the current contents of the ArrayList in the debug immediate window.
<br />
Public Class Form1<br />
Dim myNumbers As New ArrayList<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim iMyRnd As Integer<br />
<br />
' Initialize the random-number generator.<br />
Randomize()<br />
' Generate random value between 1 and 10.<br />
iMyRnd = CInt(Int((10 * Rnd()) + 1))<br />
<br />
If (myNumbers.IndexOf(iMyRnd) < 0) Then<br />
myNumbers.Add(iMyRnd)<br />
Me.RichTextBox1.Text = Me.RichTextBox1.Text + vbCrLf + CStr(iMyRnd)<br />
Else<br />
MsgBox("Already generated number: " + CStr(iMyRnd))<br />
End If<br />
End Sub<br />
<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
Dim i As Integer<br />
<br />
For i = 0 To myNumbers.Count - 1<br />
Debug.Print(myNumbers(i).ToString)<br />
Next<br />
End Sub<br />
End Class<br />
|
|
|
|
|
hello sir
first of all thank you very much for your rep.
it works fine but i have done some thing like this , and it's not showing same question again
is this right way to do it ?
If AskedQ >= ArraySize Then<br />
MessageBox.Show("Finish want to play again..?", "Finish", MessageBoxButtons.OK)<br />
For I As Integer = 0 To ArraySize<br />
Asked(I) = False<br />
AskedQ = 0<br />
Next<br />
txtQ.Text = "" : txtA.Text = "" : txtB.Text = "" : txtC.Text = "" : txtD.Text = ""<br />
Button1.Enabled = True : Button2.Enabled = True<br />
Exit Sub<br />
Else<br />
Try<br />
Do<br />
odaTest.Fill(dsTest)<br />
R = CInt(Int(ArraySize * Rnd()))<br />
<br />
'[Go to the next entry]<br />
Me.BindingContext(dsTest, "MyTest").Position = R<br />
Loop Until Asked(R) = False<br />
<br />
AskedQ += 1<br />
Asked(R) = True<br />
Catch eLoad As System.Exception<br />
MessageBox.Show(eLoad.Message)<br />
End Try<br />
'[See custom procedures]<br />
Me.dsContacts_PositionChanged()<br />
End If
thanks again
|
|
|
|
|
I am trying to send data using sockets and tcpClient. I got all the code written from an example I found in a book. But, it gave an example about having the server and client on the same unit. So the code is as follows.
Client
<code>dim tcpcli as new Sockets.tcpclient("localhost", 2001)</code> 'This looks at local host address.
My question is how do I put in a different pc address. I tried putting in pc IP like 192.112.10.116.
dim tcpcli as new Sockets.tcpclient("192.112.10.116", 2001) did not work
Can someone give me an example of how I would do this?
Thank you.
modified on Thursday, March 13, 2008 4:41 PM
|
|
|
|
|
Dim tcpcli As New Net.Sockets.TcpClient(New Net.IPEndPoint(Net.IPAddress.Parse("192.112.10.116"), 2001))
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
When I do this I get this error?
The requested address is not valid in its context.
I can't figure it out. Any Ideas.
|
|
|
|
|
can your computer get to that address? ex: \\192.168... or can you ping it?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Yes, I can ping and access a shared folder on the device which is a barcode scanner with Windows CE. I don't think that would make a difference.
|
|
|
|
|
????
google "The requested address is not valid in its context" and see what the fix is...
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Can you walk me through how Sockets work? Maybe I am trying to do something and it is wrong. This is what I think my code is trying to do. Correct me if I am wrong.
Server Side
Listener code 'Most of this code I found in a book.
Dim localhostAddress As IPAddress = IPAddress.Loopback
Dim tcpList As New TcpListener(localhostAddress, 2048) 'I just picked a port not already being used.
tcpList.Start()
Do
Dim tcpcli As TcpClient = tcpList.AcceptTcpClient
Dim ns As NetworkStream = tcpcli.GetStream
Dim sr As New StreamReader(ns)
Dim receivedData As String = sr.ReadLine()
Dim result As Boolean
If receivedData <> "" Then
'Test the received data to see which function to call
If receivedData = "BUYER" Then
result = desktop.getBuyers()
ElseIf receivedData = "SHIP" Then
result = desktop.updateShip()
ElseIf receivedData = "MOVE" Then
result = desktop.updateMove()
ElseIf receivedData = "PHYINV" Then
result = desktop.updatePhyInv()
End If
'Send result
SendData(ns, result)
End If
sr.Close()
ns.Close()
tcpcli.Close()
If receivedData = "" Then Exit Do
Loop
tcpList.Stop()
Client side code I want to send data across a wireless device to my pc to my running application. Is this code on the right track?
<code>Dim sock As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim ipep As IPEndPoint = New IPEndPoint(IPAddress.Parse("110.156.10.116"), 2048)
sock.Connect(ipep)
Dim ns As NetworkStream = New NetworkStream(sock)
Dim sw As New StreamWriter(ns)
sw.WriteLine("BUYER")
sw.Flush()
Dim result As String = ReadData(ns)
sw.Close()
ns.Close()
If result <> "" Then Exit Do
Loop
</code>
The above IP for the socket is to my pc. Does the port have to match the one it is going to on the other end?
Any help is appreciated.
|
|
|
|
|
Hi,
I am using VB to grab information from Monarch Pro and output it into a printable format, I have been putting it into a txt file and need a way to input a page break into the output, I am able to use Word if that helps. I can also use other methods of parcing the data, I just need a little push in the right direction, it would be best to put the information into a format that a user could open,print and go.
|
|
|
|
|
Chris Dykes wrote: I have been putting it into a txt file and need a way to input a page break into the output,
There is no such thing as a pagebreak in a text file. The closest you're going to get is the FormFeed character (ASCII code 12). Of course, there are other formats you could use besides straight text. But, keep in mind that pagebreaks are a function of the application doing the printing, not of the document. The document needs to convey that there should be a pagebreak at a certain point in the document and signal that by including the appropriate formatting codes in the file. Exactly how to do this depends on the file format chosen and the application printing it.
|
|
|
|
|
So if I use Word to print the document I would format it to what Word requires for page breaks?
|
|
|
|
|
You'd more than likely be using Word's object model to build the document, which will probably include a method to insert a pagebreak.
|
|
|
|
|
Hi,
I'm a little confused about sending a variable into a function ByVal. I've always understood it that if you send it by value the program will make a copy of the variable and anything you do to that variable inside the function will not affect the original one. Thing is my code seems to contradict this. (i hate it when people post loads of code so i've simplified it)
class SomeClass
' a ticket has a property .Message which is a Mymailer.Message
private ticket as MyMailer.Ticket
private function DoSomething(ByVal message as MyMailer.Message) as Mymailer.Message
message.Subject = "Test subject"
message.Body = "This is a test message"
return message
end function
private sub SomeSubroutine()
dim newMessage as MyMailer.Message = DoMailMerge(ticket.Message)
end sub
end class
for some reason when i call SomeSubroutine() the message contained in the variable 'ticket' is changed, even though i passed it by value.
can anyone see why the variable ticket would be affected?
it works if the DoSomething function is:
private function DoSomething(ByVal message as MyMailer.Message) as Mymailer.Message
dim subject as string = "TestSubject"
dim body as string = "This is a test message"
dim newmessage as new MyMailer.Message
newmessage.Subject = subject
newmessage.Body = body
return newmessage
end function
kevin
|
|
|
|
|
If your object is a reference type ( a class ) then ByVal means nothing, it's always ByRef
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|