HelpVisualBasic and a program to convert time

Posts 1–12 of 12 · Page 1 of 1
VisualBasic and a program to convert time
Hello,

I am studying Visual Basic on school. We open Excel and on programmer tab, under visual basic, we code.
Thing is, I'm stuck with this one, I need a program that converts time in seconds to time in format hours:minutes:seconds
Like, when I type 6, it converts to 00:00:06 or 3673 to 01:01:13.

Currently the code (it's wrong, I know) it's like this:

Code:
Public Sub ConversorTempo()   
 Dim z As Integer
    z = Val(InputBox("Digite o número em segundos."))
    MsgBox ("O tempo em horas, minutos e segundos é" & z / 3600 & "Horas " & (z / 3600) / 60 & "Minutos " & ((z / 3600) / 60) / z & "Segundos.")
    End Sub
Kinda have no clue of what I am doing. So if anyone could give me the code to the working program so that I can study it.
Thanks in advance and sorry for bothering. I have a feeling this is not as complex as it seems to me, but I am kinda stuck.
I have other VB problems, so I'll leave this one to you. thanks once more.
Timeofday.addhour(int)
Quote Originally Posted by wut12345 View Post
Timeofday.addhour(int)
Not working...
Its like this?

Code:
Public Sub Calculadora()
    
Timeofday.addhour(int)
        
End Sub
. . . . .. . . . . . . . . . . ,.-‘". . . . . . . . . .``~.,
. . . . . . . .. . . . . .,.-". . . . . . . . . . . . . . . . . ."-.,
. . . . .. . . . . . ..,/. . . . . . . . . . . . . . . . . . . . . . . ":,
. . . . . . . .. .,?. . . . . . . . . . . . . . . . . . . . . . . . . . .,
. . . . . . . . . /. . . . . . . . . . . . . . . . . . . . . . . . . . . . ,}
. . . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . . ,:`^`.}
. . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . ,:". . . ./
. . . . . . .?. . . __. . . . . . . . . . . . . . . . . . . . :`. . . ./
. . . . . . . /__.(. . ."~-,_. . . . . . . . . . . . . . ,:`. . . .. ./
. . . . . . /(_. . "~,_. . . .."~,_. . . . . . . . . .,:`. . . . _/
. . . .. .{.._$;_. . ."=,_. . . ."-,_. . . ,.-~-,}, .~"; /. .. .}
. . .. . .((. . .*~_. . . ."=-._. . .";,,./`. . /" . . . ./. .. ../
. . . .. . .`~,. . .."~.,. . . . . . . . . ..`. . .}. . . . . . ../
. . . . . .(. ..`=-,,. . . .`. . . . . . . . . . . ..(. . . ;_,,-"
. . . . . ../.`~,. . ..`-.. . . . . . . . . . . . . . ... . /
. . . . . . `~.*-,. . . . . . . . . . . . . . . . . ..|,./.....,__
,,_. . . . . }.>-._. . . . . . . . . . . . . . . . . .|. . . . . . ..`=~-,
. .. `=~-,__. . . `,. . . . . . . . . . . . . . . . .
. . . . . . . . . .`=~-,,.,. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . `:,, . . . . . . . . . . . . . `. . . . . . ..__
. . . . . . . . . . . . . . . . . . .`=-,. . . . . . . . . .,%`>--==``
. . . . . . . . . . . . . . . . . . . . _. . . . . ._,-%. . . ..`
Quote Originally Posted by wut12345 View Post
. . . . .. . . . . . . . . . . ,.-‘". . . . . . . . . .``~.,
. . . . . . . .. . . . . .,.-". . . . . . . . . . . . . . . . . ."-.,
. . . . .. . . . . . ..,/. . . . . . . . . . . . . . . . . . . . . . . ":,
. . . . . . . .. .,?. . . . . . . . . . . . . . . . . . . . . . . . . . .,
. . . . . . . . . /. . . . . . . . . . . . . . . . . . . . . . . . . . . . ,}
. . . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . . ,:`^`.}
. . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . ,:". . . ./
. . . . . . .?. . . __. . . . . . . . . . . . . . . . . . . . :`. . . ./
. . . . . . . /__.(. . ."~-,_. . . . . . . . . . . . . . ,:`. . . .. ./
. . . . . . /(_. . "~,_. . . .."~,_. . . . . . . . . .,:`. . . . _/
. . . .. .{.._$;_. . ."=,_. . . ."-,_. . . ,.-~-,}, .~"; /. .. .}
. . .. . .((. . .*~_. . . ."=-._. . .";,,./`. . /" . . . ./. .. ../
. . . .. . .`~,. . .."~.,. . . . . . . . . ..`. . .}. . . . . . ../
. . . . . .(. ..`=-,,. . . .`. . . . . . . . . . . ..(. . . ;_,,-"
. . . . . ../.`~,. . ..`-.. . . . . . . . . . . . . . ... . /
. . . . . . `~.*-,. . . . . . . . . . . . . . . . . ..|,./.....,__
,,_. . . . . }.>-._. . . . . . . . . . . . . . . . . .|. . . . . . ..`=~-,
. .. `=~-,__. . . `,. . . . . . . . . . . . . . . . .
. . . . . . . . . .`=~-,,.,. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . `:,, . . . . . . . . . . . . . `. . . . . . ..__
. . . . . . . . . . . . . . . . . . .`=-,. . . . . . . . . .,%`>--==``
. . . . . . . . . . . . . . . . . . . . _. . . . . ._,-%. . . ..`
Sorry dude, Im just like "no skill attached" when it comes to this.
Can you explain it again?
When I open Excel, and after clicking on VisualBasic under Programmer Tab, what do I do? What code am I to put there to make a calculator sub routine?
Code:
dim iSecond as double = 0 'Total number of seconds
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(iSecond)

lblHours.Text = iSpan.Hours.ToString.PadLeft(2, "0"c)
lblMinutes.Text = iSpan.Minutes.ToString.PadLeft(2, "0"c)
lblSeconds.Text = iSpan.Seconds.ToString.PadLeft(2, "0"c)

txtFormattedTime.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & _
                        iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & _
                        iSpan.Seconds.ToString.PadLeft(2, "0"c)
Quote Originally Posted by Rance-Sama View Post
Code:
dim iSecond as double = 0 'Total number of seconds
Dim iSpan As TimeSpan = TimeSpan.FromSeconds(iSecond)

lblHours.Text = iSpan.Hours.ToString.PadLeft(2, "0"c)
lblMinutes.Text = iSpan.Minutes.ToString.PadLeft(2, "0"c)
lblSeconds.Text = iSpan.Seconds.ToString.PadLeft(2, "0"c)

txtFormattedTime.Text = iSpan.Hours.ToString.PadLeft(2, "0"c) & ":" & _
                        iSpan.Minutes.ToString.PadLeft(2, "0"c) & ":" & _
                        iSpan.Seconds.ToString.PadLeft(2, "0"c)
For some reason when I paste this it becomes red.

Wait... there's something you havent realized. There is no interface, its just a sub routine made in excel.
so I didnt made any labels or textboxes inside a form. I just write code there.
Here you go.

Public Sub ConversorTempo()
Dim z As Integer = Val(InputBox("Digite o número em segundos."))
Dim Time As TimeSpan = TimeSpan.FromSeconds(z) ' Create out TimeSpan Object.
MsgBox("O tempo em horas, minutos e segundos é" & Time.Seconds & " Horas " & Time.Minutes & " Minutos " & Time.Seconds & " Segundos.") ' Output
End Sub
Quote Originally Posted by consca View Post
Here you go. Public Sub ConversorTempo() Dim z As Integer = Val(InputBox("Digite o número em segundos.")) Dim Time As TimeSpan = TimeSpan.FromSeconds(z) ' Create out TimeSpan Object. MsgBox("O tempo em horas, minutos e segundos é" & Time.Seconds & " Horas " & Time.Minutes & " Minutos " & Time.Seconds & " Segundos.") ' Output End Sub
Thanks but there is one thing: for some reason, when I paste the code, it seems that, as when I pasted wut12345's code, it gives me error after the Dim Time as TimeSpan and Dim z as Integer = (that "=" doesnt bode well somehow, do you know why is that?)
If you'd like someone to comment about the error..please post the exact error message you got, else we can't help much..it's only a couple lines of code and doesn't have any super obvious bugs. Screenshot would be best. To include the image directly in a post, use the bbcode tags [ img ] www addressdotcom / image.jpg [ / img ] (without spaces).

ex. [ i m g ] https://www.google.com/images/srpr/logo11w.png [ / i m g ]
results in

can you give the link of visual basic for download .. I really need it if you have
Quote Originally Posted by DarkChibiKun View Post
can you give the link of visual basic for download .. I really need it if you have
What are you talking about? Go get the 'Free' Visual Studio Express. VB.net is included.
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us