i want to convert total minutes into days hours and minutes. i am new to vb and still trying to learn...
this is my code...
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
TextBox1.Text = TextBox3.Text / 1440
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
TextBox3.Text = TextBox1.Text * 1440
TextBox7.Text = TextBox1.Text / 24
End Sub
Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
TextBox1.Text = TextBox7.Text * 24
End Sub
When i run it i am having answers in decimal.. can anyone suggest me a proper way to do this? i do not want decimals.
It doesn't look like you understand the concept of variables, you don't need to have three different handlers to make this work, you can do it all in one handler.
You could do what you want arithmetically but in my opinion, an easier way is to use TimeSpan. It would look something like this:
'TextBox1 is where the user inputs the number of minutes
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim d = TimeSpan.FromMinutes(TextBox1.Text) 'creates a TimeSpan based on user input, this is also a variable creation
TextBox5.Text = d.ToString("dd\:hh\:mm") 'you can format it with a custom format
'Or you can access the elements of the TimeSpan like so
TextBox2.Text = d.Days
TextBox3.Text = d.Hours
TextBox4.Text = d.Minutes
End Sub
Related
Basically i want one textbox to do this:
TextBox5.Text = TextBox4.Text / TextBox2.Text
It works but if i don't try to input something to the textbox it doesn't update. How do i ?
You can handle both TextBox_TextChanged events, and try to parse the strings as doubles. If both succeed, then do the math and update the TextBox.
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
doMath()
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
doMath()
End Sub
Private Sub doMath()
Dim tb2 As Double, tb4 As Double
If Double.TryParse(TextBox2.Text, tb2) AndAlso Double.TryParse(TextBox4.Text, tb4) Then
TextBox5.Text = (tb4 / tb2).ToString()
Else
TextBox5.Text = ""
End If
End Sub
The TextBox will be updated immediately with the quotient when both other TextBoxes are valid doubles.
Remember not to try to do math using strings. You may want to put Option Strict On at the top of your code file so the compiler tells you you can't do math with strings like this TextBox4.Text / TextBox2.Text
I need to know the value of time. I mean the interval of time; from starting time to ending time. Anyone can help? :(
This is my list and I want to get the interval value of time.
When I select the item/record in the Datagridview2 it will displayed here
Can somebody share an idea/or code? Thanks
To achieve something like this, you need the TimeSpan data type.
In my example, a variable is written with the current time at the beginning of the runtime.
A timer regularly calculates the new time span between time 1 and the current time, and outputs this time span in a text box.
Also, I use CultureInfo (I always do, don't be surprised) and I use PadLeft to have leading zeros. Looks nicer.
Public Class FormMain
Private ReadOnly Starttime As Date = Date.Now
Private ReadOnly Deu As New System.Globalization.CultureInfo("de-DE")
Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim TS As TimeSpan = Date.Now - Starttime
TextBox1.Text = TS.Minutes.ToString(Deu).PadLeft(2, "0"c) & ":" & TS.Seconds.ToString(Deu).PadLeft(2, "0"c)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
End Class
So, I'm making a VB.NET software, and want to show minute format as XX minute, e.g: "05 minute left" and not like this: "5 minute left." My code now like this:
min = DateTime.Now.ToString("mm") + NumericUpDown2.Value
I've tried with big "MM" letters but it's just another time format.
Is that a countdown application, and when I'm try to check the time failed.
If Date.Time.Minutes = min Than
Alarm.show
End If
Although this code has not been tested it should give you some ideas of how to proceed. As far as the formatting is concerned - right pew, wrong church. Number.ToString("00")
Private AlarmTime As DateTime
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AlarmTime = DateTime.Now.AddMinutes(NumericUpDown1.Value)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim TimeLeft As TimeSpan = AlarmTime - DateTime.Now
Dim MinutesLeft As Integer = TimeLeft.Minutes
Label1.Text = MinutesLeft.ToString("00")
If AlarmTime >= DateTime.Now Then
Alarm.Show()
Timer1.Enabled = False
End If
End Sub
The right way to do this is like this:
DateTime.Now.Minute.ToString("00")
I need it so the next number generated is greater than the last... this is my first project with object-oriented programming, so I don't know much. Also, how do I make it so it runs a certain number of simulations before it lands on a number grouping? It would be greatly appreciated.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As Object, e As EventArgs) Handles Button1.Click
Randomize()
TextBox1.Text = Rand(1, 100)
TextBox2.Text = Rand(1, 100)
TextBox3.Text = Rand(1, 100)
TextBox4.Text = Rand(1, 100)
TextBox5.Text = Rand(1, 100)
TextBox6.Text = Rand(1, 100)
TextBox7.Text = Rand(1, 100)
TextBox8.Text = Rand(1, 200)
End Sub
Public Function Rand(ByVal Low As Long, ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd()) + Low
End Function
End Class
Without getting into any other coding issues with your example:
TextBox2.Text = Rand(Long.Parse(TextBox1.Text), 100)
TextBox3.Text = Rand(Long.Parse(TextBox2.Text), 100)
' ... etc.
The 100 is based off your code, you may have some algorithm for setting the next higher range other than set values. If your first random number is 100 then the rest of your calculations are going to be non-random!
Create a list of the text boxes you want to fill at the form level.
Private lstTextBoxes As List(Of TextBox)
Fill the list in the Form.Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lstTextBoxes = New List(Of TextBox) From {TextBox1, TextBox2, TextBox3}
End Sub
Use the .net Random class. It is easier than the old one.
Private Rand As New Random
Now you can loop through your text boxes and fill with a "random" number. Each iteration will be a higher number than the last but will stop when it reaches 100.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim highNumber As Integer
For Each txtBox As TextBox In lstTextBoxes
If highNumber >= 99 Then
Return
End If
highNumber = Rand.Next(highNumber + 1, 100)
txtBox.Text = highNumber.ToString
Next
End Sub
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have start to build a bot and i have try to get the mouse position store on a variable x and y and then wen i click start move the mouse to the location but wen i start the bot the location its not right.
How can i get the true position of it.
I have try like this but i cant get the correct position of mouse x,y inside of a webbrowser
I have made a gif image of the problem imgur link https://imgur.com/a/QQLQX
I have also edit my code and try a different way but i can not get the correct position
This is my code
Public Class Form1
Dim horas
Dim minutos
Dim segundos
Dim milesimos
Dim ratobutao
Dim tipoclick
Dim repetir
Dim currentelocal
Dim xmouse
Dim ymouse
Dim WithEvents htmldoc As HtmlDocument
Private Sub htmldoc_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseMove
'TextBox5.Text = e.MousePosition.X.ToString
'TextBox6.Text = e.MousePosition.Y.ToString
'xmouse = e.MousePosition.X.ToString
'ymouse = e.MousePosition.Y.ToString
End Sub
Private Sub htmldoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseDown
'xmouse = e.MousePosition.X.ToString
'ymouse = e.MousePosition.Y.ToString
'TextBox5.Text = e.MousePosition.X.ToString
'TextBox6.Text = e.MousePosition.Y.ToString
xmouse = Me.Width / WebBrowser1.Width
ymouse = Me.Height / WebBrowser1.Height
TextBox5.Text = e.MousePosition.X.ToString
TextBox6.Text = e.MousePosition.Y.ToString
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("www.google.com")
For Each c As Control In Controls
AddHandler c.MouseClick, AddressOf ClickHandler
Next
End Sub
Private Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
Select Case e.Button
Case MouseButtons.Left
MsgBox("left mouse")
TextBox5.Text = xmouse
TextBox6.Text = ymouse
Label2.Text = "Left"
Case MouseButtons.Right
Label2.Text = "Right"
Case MouseButtons.Middle
Label2.Text = "Middle"
Case Else
Label2.Text = "Some other button"
End Select
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
htmldoc = WebBrowser1.Document
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox5.Text = xmouse
TextBox6.Text = ymouse
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Windows.Forms.Cursor.Position = New Point(xmouse, ymouse)
Timer1.Stop()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Timer1.Start()
End Sub
End Class
When programming with graphical interfaces, there are three different coordinate sets you need to be aware of: Screen, Window, and Client. Different contexts provide coordinates from different areas. You need to know what type of coordinates you have, and how to convert between the others. This image illustrates:
In multi-monitor situations there may even be a fourth, to differentiate between a specific monitor and the entire desktop. Different windowing systems may also argue about what section counts as the client area, but the main thing is it's not the same as the others.
Figure out what coordinates you have in each situation in your code, and then look up how to convert between them.
In fact after to try many different ways to get it .
I have solve the mystery :)
It is easy but there not that many information out there about, and well English its not my native Language and the way i try to search maybe not that efficient.
But i get it work perfect.
This is the working code
Private Sub htmldoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs) Handles htmldoc.MouseDown
xmouse = Control.MousePosition.X.ToString()
ymouse = Control.MousePosition.Y.ToString()
TextBox5.Text = xmouse
TextBox6.Text = ymouse
End Sub