I have a masked textbox with time value ("hh:mm" the duration the task wil take) and a combo box with 1-10.
How do I mutilply the masked textbox with the combo box to get the total dutation it would take in "hh:mm.
I have txttime1 as the first textbox that holds the time. (masked textbox)
Cmb1 with 1-10, this indicates how many times the txttime1 must be multiplied.
Txtdura1 as the answer to the multiplication. Basically the total duration of the event.
Any direction would be great.
Convert the string from the textbox to a TimeSpan. Then change to TotalMinutes which is a Double so you can perform multiplication. Take the result of the multiplication and change it to a TimeSpan .FromMinutes. You can then format the result in various ways.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim ts As TimeSpan = TimeSpan.ParseExact(TextBox2.Text, "h\:m", CultureInfo.CurrentCulture)
Dim dblTotalMinutes As Double = ts.TotalMinutes
Dim Multiplier As Integer = CInt(ComboBox1.SelectedItem)
Dim MultipliedMinutes As Double = dblTotalMinutes * Multiplier
Dim MultipliedTimeSpan As TimeSpan = TimeSpan.FromMinutes(MultipliedMinutes)
'For days:hours:minutes
TextBox3.Text = MultipliedTimeSpan.ToString("d\:hh\:mm")
'Total Hours as double
TextBox4.Text = MultipliedTimeSpan.TotalHours.ToString
End Sub
Split the hours and minutes apart from each other, create a TimeSpan object and multiply that by the factor from the ComboBox:
Dim duration As TimeSpan = TimeSpan.Parse(txttime1.Text)
Txtdura1 = duration.Multiply(Integer.Parse(Cmb1.Text)).ToString("hh\:mm")
Relevant documentation:
TimeSpan.Parse()
TimeSpan.Multiply()
TimeSpan.ToString()
Related
I'm close to finishing a small program that i started, but got stuck with the last part. And I'm just starting to learn programming, so might be a stupid question.
How can i get the text box with the highest number out of 16 boxes,each having its own number, but at the same time keep track of which one still has the highest number every second? Quite confused about the updating it every second part.
All help is appreciated!
Code suggestion
Private Sub findTopTextBox()
Dim topValue As Integer
Dim topTextBox As TextBox
For Each ctrl As Control In Me.Controls 'all the controls on your form
If TypeOf ctrl Is TextBox Then
Dim thisValue As Integer
If Integer.TryParse(DirectCast(ctrl, TextBox).Text, thisValue) Then
If thisValue > topValue Then
topValue = thisValue
topTextBox = DirectCast(ctrl, TextBox)
End If
End If
End If
Next
Debug.Print(String.Concat(topTextBox.Name, " has the top value at: ", topValue))
End Sub
In order to test it each second, you'll need to add a Timer and call this method repeatedly.
You don't really need to check every second only check when a change was made in one of those textboxes
You could handle all your textboxes LostFocus event (using the same method to handle them all) ; get it's text, verify it's a number and if it's greater than the current max update it (along with it's "location" : the textbox control)
That way you always know which one is the greatest
Something along this should do it (typed directly here so not tested) :
Dim maxNumber As Integer, maxTextBox As TextBox
Sub TextBoxes_LostFocus(sender As Object, e As EventArgs) Handles textbox1.LostFocus, textbox2.LostFocus ' ... for all textboxes
Dim tbSender = DirectCast(sender, TextBox)
Dim number As Integer
' Should we update maxTextBox if number = maxNumber ? (if yes change the > to >=)
If Integer.TryParse(tbSender.Text, number) AndAlso number > maxNumber Then
maxNumber = number
maxTexBox = tbSender
End If
End Sub
I have 2 textbox in vb.net form.
In one textbox it displays system time.
In second textbox i want to display time that is 2 hrs later than system time.
How can i do that with timespan.
Does it have to be a timespan? You can do it with a Date variable.
Dim dt As Date = Date.Now
textbox1.Text = dt.ToString()
textbox2.Text = AddTimeZoneDiff(2, dt)
Private Function AddTimeZoneDiff(offset As Double, dt As Date) As String
Return dt.AddHours(offset).ToShortTimeString()
End Function
Hello on my project I am using vb and I have a datagridview binding with datasource.
For example I have this columns name
StartTime- this show the time a job started
7:00 am
4:30 pm
Hours- how long that job is going to run
30 minutes
2 HOURS
I want to be able to add the compute remaining time to each row that is inserted into the datagridview.
I already have a column name remainingTime that is not binding to the datasource. How can i add the compute remainingtime to each row. Even when the user inserted a new row? I already calculate the remainingTime but it only do this for the first row.
In my Form Load I have
Dim myTime As Date
'RemainingTime
Dim totalTime As Date = runningJobs_list.Rows(0).Cells(5).Value
' Dim totalTime As Date = runningJobs_list.Rows(0).Cells(5).Value
myTime = totalTime.AddHours(runningJobs_list.Rows(0).Cells(6).Value)
' myTime = totalTime.AddHours(runningJobs_list.Rows(0).Cells(6).Value)
Timer.Start()
this is my timer to do the countdown of reaming time
Private Sub Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
'variable to compare two timespan
Dim myspan As TimeSpan
myspan = TimeSpan.Zero
'decrease myTime to actual system time
Dim remainingTime As TimeSpan = myTime.Subtract(Date.Now)
'if the remaining time is less than zero then set red the entire row otherwise decrease timer
If remainingTime < myspan Then
runningJobs_list.Rows(0).DefaultCellStyle.BackColor = Color.Red
Else
runningJobs_list.Rows(0).Cells(8).Value = remainingTime
End If
End Sub
Please could someone help me?
You have to wrap that calculation into foreach loop which loops through all rows in grid (except last empty row. Check for rows IsNewRow status, or if Cells(0).Text is empty to validate is it empty or not...)
So this:
runningJobs_list.Rows(0).Cells(8).Value = ...
Should be something like this:
ForEach gridRow As DataGridRow in runningJobs_List.Rows
gridRow.Cells(8).Value = ...<br />
Next
I'm trying to make the label's time change every second to match the time of the media being played.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim remain As Int32 = AxWindowsMediaPlayer1.currentMedia.duration - AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Dim Minutes As String
Dim Secs As String
Dim ElapsedTime As String
Minutes = (remain / 60).ToString("00")
Secs = (remain Mod 60).ToString("00.00")
ElapsedTime = Minutes & "." & Secs
Label1.Text = ElapsedTime ' Display the remaining time for the .wav file in a label in mm:ss format
TrackBar2.Value = ElapsedTime (Error with this line: Conversion from string "11.26.00" to type 'Integer' is not valid.)
End Sub
Do I change the strings to integers instead?
I think its a matter of the compiler not being able to implicitly convert the values, I would either change the format of the string or do something like this:
Dim totalTime as Integer = 0
For Each thing In ElapsedTime.Split(".")
totalTime += CInt(thing) 'So, "11.26.00" will turn into 11 + 26 + 0 = 37 for totalTime
Next
That's just a simple outline, you can do any additional arithmetic as needed.
As per the docs here, a trackbar needs to have its value set to an integer somewhere between the minimum and maximum.
That will be 0 and 10 if you're using the default minimum and maximum, or something else if you've changed them (obviously).
You need to figure out how to change the time string (or time remaining integer, remain) into a value between that minimum and maximum, then set the value to that.
Since you have the duration and position, you can possibly use something like:
Dim pos as Int32 = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Dim tot as Int32 = AxWindowsMediaPlayer1.currentMedia.duration
Dim tenthsToGo as Int32 = 10 * (tot - pos) / tot
' Now use tenthsToGo (or 10-tenthsToGo depending on direction) to set trackbar '
If you have set the maximum to be the duration (and left the minimum at zero) as seems to be indicated in a comment, then you can simply set the trackbar value to the current position (which varies from 0 to the maximum).
can you use this code to display time of media player when played and duration of song or video it play sory 4 bad english
TrackBar2.Maximum = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.duration
Label3.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString
TrackBar2.Value = AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
Label4.Text = AxWindowsMediaPlayer1.Ctlcontrols.currentItem.durationString
I want to make a program that depending on which radio buttons someone clicks (only 1 button per GroupBox) and a total of 5 different group boxes. a specific value would be added To a num1Textbox Value that was entered.
The question is Can it be done? or am i wasting my time trying to learn it. I am very new to VB.. and have only done a cpl programs that add - mulitpy - divide and subtract values for the golf program for putting.. this time it will be more complicated I know.
Below is a pic of the program.
Someone would enter Yard to Hole = 145 (would be different number each time)
They would then select 1 radio button per GroupBox (5 different options) and the value 145 would increase or decrease accordingly depending which options is selected.
Sorry it would not allow me to uplaod a picture here :( so i uploaded it here.
sorry did not know you needed an account to view form there.. i will try to find a new place. 1 min
lets try here
http://i1311.photobucket.com/albums/s667/Steve_Lunney/design_zps9c2f89da.jpg
ANY help would be greatly appreciated... Thank you in advance
this is what i was trying.. as someones suggestion
but under each of these staements spinGroupBox.spin1RadioButton.Checked I get wavy lines and when i put my mouse over it it says - 'upRadioButton' is not a member of 'System.Windows.Forms.Groupbox"
Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
Dim spinGroupBox As New GroupBox()
Dim spin1RadioButton As RadioButton
Dim spin2RadioButton As RadioButton
Dim spin3RadioButton As RadioButton
Dim spin4RadioButton As RadioButton
Dim spin5RadioButton As RadioButton
Dim num1TextBox As Integer
Dim num2TextBox As Integer
Dim spin1b As Decimal
Dim resultA As Integer
Select Case True
Case spinGroupBox.spin1RadioButton.Checked
spin1b = 0.095
Case spinGroupBox.spin2RadioButton.Checked
spin1b = 0.085
Case spinGroupBox.spin3RadioButton.Checked
spin1b = 0.08
'etc
End Select
resultA = spin1b
' Create and initialize a GroupBox and a Button control.
Dim windGroupBox As GroupBox
Dim upRadioButton As RadioButton
Dim ulRadioButton As RadioButton
Dim urRadioButton As RadioButton
Dim downRadioButton As RadioButton
Dim dlRadioButton As RadioButton
Dim drRadioButton As RadioButton
Dim leftRadioButton As RadioButton
Dim rightRadioButton As RadioButton
Dim wind1b As Decimal
Dim resultb As Integer
Select Case True
Case windGroupBox.upRadioButton.Checked
wind1b = 0.095
Case windGroupBox.ulRadioButton.Checked
wind1b = 0.085
Case windGroupBox.urRadioButton.Checked
wind1b = 0.075
Case windGroupBox.downRadioButton.Checked
wind1b = 0.07
Case windGroupBox.dlRadioButton.Checked
wind1b = 0.065
Case windGroupBox.drRadioButton.Checked
wind1b = 0.06
Case windGroupBox.leftRadioButton.Checked
wind1b = 0.055
Case windGroupBox.rightRadioButton.Checked
wind1b = 0.05
End Select
resultb = wind1b
End Sub
I have tested it now, and as I posted in the comment, upRadioButton (and all the others) are (most probably) direct children of the form. That means you can write
Case Me.upRadioButton.Checked
(or you can leave out the Me.)
Btw., if you have pulled the controls onto the form in the designer, you should remove those dim ... lines. The controls are declared in another file that is hidden by default. Your lines declare variables again that shadow the access to the actual form controls, meaning that you get errors when you try to access them without Me..