|
Dave Kreskowiak wrote: ubiquitous homework assignment
I remember those kind of assignments from a long, long, long time ago
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
This is a common homework problem, I'm sure there's code to be found to do it. Essentially, you just parse the parts of the number and build your text representation of it.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Here's something i found, might help you.
<br />
=SpellNumber(32.50)<br />
<br />
<br />
Option Explicit<br />
<br />
'****************<br />
' Main Function *<br />
'****************<br />
Function SpellNumber(ByVal MyNumber)<br />
Dim Dollars, Cents, Temp<br />
Dim DecimalPlace, Count<br />
<br />
ReDim Place(9) As String<br />
Place(2) = " Thousand "<br />
Place(3) = " Million "<br />
Place(4) = " Billion "<br />
Place(5) = " Trillion "<br />
<br />
' String representation of amount<br />
MyNumber = Trim(Str(MyNumber))<br />
<br />
' Position of decimal place 0 if none<br />
DecimalPlace = InStr(MyNumber, ".")<br />
'Convert cents and set MyNumber to dollar amount<br />
If DecimalPlace > 0 Then<br />
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))<br />
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))<br />
End If<br />
<br />
Count = 1<br />
Do While MyNumber <> ""<br />
Temp = GetHundreds(Right(MyNumber, 3))<br />
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars<br />
If Len(MyNumber) > 3 Then<br />
MyNumber = Left(MyNumber, Len(MyNumber) - 3)<br />
Else<br />
MyNumber = ""<br />
End If<br />
Count = Count + 1<br />
Loop<br />
<br />
Select Case Dollars<br />
Case ""<br />
Dollars = "No Dollars"<br />
Case "One"<br />
Dollars = "One Dollar"<br />
Case Else<br />
Dollars = Dollars & " Dollars"<br />
End Select<br />
<br />
Select Case Cents<br />
Case ""<br />
Cents = " and No Cents"<br />
Case "One"<br />
Cents = " and One Cent"<br />
Case Else<br />
Cents = " and " & Cents & " Cents"<br />
End Select<br />
<br />
SpellNumber = Dollars & Cents<br />
End Function<br />
<br />
'*******************************************<br />
' Converts a number from 100-999 into text *<br />
'*******************************************<br />
Function GetHundreds(ByVal MyNumber)<br />
Dim Result As String<br />
<br />
If Val(MyNumber) = 0 Then Exit Function<br />
MyNumber = Right("000" & MyNumber, 3)<br />
<br />
'Convert the hundreds place<br />
If Mid(MyNumber, 1, 1) <> "0" Then<br />
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "<br />
End If<br />
<br />
'Convert the tens and ones place<br />
If Mid(MyNumber, 2, 1) <> "0" Then<br />
Result = Result & GetTens(Mid(MyNumber, 2))<br />
Else<br />
Result = Result & GetDigit(Mid(MyNumber, 3))<br />
End If<br />
<br />
GetHundreds = Result<br />
End Function<br />
|
|
|
|
|
Wow. I'm unimpressed. You've managed to do all of his work for him, for an obvious homewrok assignment. Congratulations on helping him fail the class.
|
|
|
|
|
Sorry, I didn't mean it.All i wanted to do was help him...
|
|
|
|
|
The most valuable skill you can have as a developer is to know how to do your own research. You absolutely must be able to find out anything you need to to teach yourself anything from new techniques to entirely new technologies. Without that ability, you'd last about a year in a career writing code, if not any computer career.
There are three points to be made with every programming project in a class.
1. How do you logically break the problem down into smaller and smaller parts and code solutions to those small problems that work together.
2. How you manage your time to accomplish the task in the given time frame.
3. And how you do the research to teach yourself about the parts you're stuck on. This includes books, internet search engines and sites, and asking for help from appropriate resources by asking the proper questions.
Showing up on a site and asking for someone to hand over the entire source code is NOT the proper question. It just bypasses the other two points completely.
He really didn't ask for the source code, but he couldn't do point number 1 either. The answer he got pointed him in the correct direction to start doing his own research into the problem.
|
|
|
|
|
Thank you for your attention and your direction to me, I will trying to use of your valuable inforamtion
Thank you
ICE
|
|
|
|
|
There is an example right here on Code Project. It walks you through the entire process of creating the code so you know exactly what is going on and how it is built up. It also shows you how to test the code too (a skill far too few developers actually know how to do)
http://www.codeproject.com/cs/design/TestFirstDevelopment.asp[^]
|
|
|
|
|
How can I place a checkbox in a column of the Datagrid in VB6? like what datagridview in .net can do..
|
|
|
|
|
Hi,
The datagrid by default does not offer checkbox as a value for any of its cells. However I have created a work-around to get around this problem.
I have placed a checkbox on the form and when the grid loads the checkbox is moved to the cell. Code attached .
************
Private Sub Form_Load()
'on the form:
'one flexgrid (named= flex1)
'one checkbox (named= tb)
Dim intX As Integer
tb.Visible = False
With flex1
.Columns(0).Width = 2000
.RowHeight = 300
tb.Caption = "Box"
tb.Width = 500
tb.Move flex1.Left + 350, flex1.Top + 250, flex1.Width / 15, flex1.Height / 199
tb.BackColor = .BackColor
tb.Visible = True
End With
End Sub
************
Gary Bigman.
Software Engineer
ComponentOne LLC
www.componentone.com
|
|
|
|
|
I have a windows app that I deploy using ClickOnce. It is available on or off-line. Currently, as soon as the app is loaded it writes to the registry setting it up to use the Application.ExecutablePath to open any files with my file extention, and also sets a default icon. This seems to work partially, (well, not at all on vista machines, but that is another problem). The problem that I am encountering, is that if a user double clicks on a file with my extention, my program will launch but it doesn't do the check to make sure the user has the most up to date version of the program. This is an issue I could live with, but another problem is also occuring.
My program allows user to save preferences (for defaults, fonts, etc) in an XML file which I save at this location:
My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
This file isn't found when the user launches the program by double clicking a file, but is found when the program is launched by the shortcut created during the ClickOnce installation.
I've seen a few other people with this problem and they were told to use URL parameters, but my users will only launch the program through an internet browser for the initial installation. After that they will use the shortcut or double click a file with my extention.
Does anyone know how I can use a ClickOnce deployment, but still get the FileAssociations to properly launch my program? I would appreciate any help or advice.
I program in VB.Net using Visual Studio 2005 on a computer running Windows XP.
|
|
|
|
|
Hi,
I recently started using VB2005 and i find it very confusing, in VB6 i used to unload form using UNLOAD ME but it doesn't work in 2005, plus i tried Me.Close() and Me.Dispose() as well but it closes my application, rather than form.
Here's the code i'm working on.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim usname As String<br />
usname = StrConv(TextBox1.Text, VbStrConv.ProperCase)<br />
If usname = "Admin" And TextBox2.Text = "pass" Then<br />
MsgBox("Welcome to Form two", MsgBoxStyle.Information + MsgBoxStyle.OkOnly)<br />
Me.Close()<br />
Form2.Show()<br />
Else<br />
MsgBox("Wrong Login details", MsgBoxStyle.Exclamation + MsgBoxStyle.RetryCancel)<br />
If MsgBoxResult.Retry Then<br />
TextBox1.Text = ""<br />
TextBox2.Text = ""<br />
TextBox1.Focus()<br />
ElseIf MsgBoxResult.Cancel Then<br />
End<br />
End If<br />
End If<br />
End Sub
can someone please help me out with this...
Thanks.
Parth Patel
|
|
|
|
|
VB6 taught you some bad habits you have to break.
In VB6, all forms exist all the time. Under true OOP and VB.NET 2005, this is not the case. A form doesn't exist until your code creates an instance of it and shows it. Your code is then responsible for disposing of it when you're done with it. Forms are classes, just like any other class in the .NET Framework you create an instance of.
Putting a Me.Close in your startup form will close your entire application because you just killed off the form that's holding your application's message pump. A form should not kill itself off. The code that created and launched it normally would do this.
You cannot transfer control from one form to another like you're trying to do. Forms get created and destroyed in a tree-like fashion. Form1 creates Form2 and shows it, which may create Form3 and show it, which may create forms 4, 5, and 6. If the instance of Form2 dies, all the forms that it created and launched, and their child forms, die along with it.
The only thing you can do to not show your Form1 and give the illusion that Form2 is now the main form is to Me.Hide() .
In the case of a login form, there's a few different ways to do this. The first is to have a Sub Main launch the puts up a form and lets it check the credentials, then returns the login state to Main. Based on that result, Main then created a second form that is the main application form.
<STAThread()> _
Shared Sub Main()
Using loginForm As New MyLoginForm
Application.Run(loginForm)
If loginForm.DialogResult = Windows.Forms.DialogResult.OK Then
If loginForm.LoginSuccessful Then
Application.Run(New MyMainForm)
End If
End If
End Using
End Sub
Of course, LoginSuccessful would probably be a public property on the login form that this code checks to see if the credentials were good. It would probably also expose the credentials or some role information as a public property too.
|
|
|
|
|
Dave Kreskowiak wrote: <stathread()> _
Shared Sub Main()
Using loginForm As New MyLoginForm
Application.Run(loginForm)
If loginForm.DialogResult = Windows.Forms.DialogResult.OK Then
If loginForm.LoginSuccessful Then
Application.Run(New MyMainForm)
End If
End If
End Using
End Sub
Thank you very much for your help, but can you please tell me where do i put this code. I'm student learning so i don't really know much about Visual Basic.
Thanks
Parth Patel
|
|
|
|
|
Either in a Module (yuk!) or in your startup form's code. Then you go into your project properties and change the Startup item to Sub Main .
|
|
|
|
|
hi there,
can someone help me on how will i pass or copy (programmatically) the information inside or declared on the datagridview1 to datagridview2.
It's like on text box.. textbox1.text = textbox2.text
i just want the datagridview2 to have the data inside the datagridview1(through a mouse click) but without the use of any dataset coz it's not binded with the sql database.
can you show me codes.
i really can't figure it out eh..
thank you so much..;)
|
|
|
|
|
without trying it:
datagridview2.datasource = datagridview1.datasource
datagridview2.datamember = datagridview1.datamember
datagridview2.refresh
???
|
|
|
|
|
this is just what i need..
I tried to use this codes and it works, with the use of some codes such as the declaration of the datatable columns.
thanks a lot..
this really helped me.
|
|
|
|
|
I have many forms in my application but I am not able to close last Form just after shited to the another Form(eg I'm in Form1 and click on button to go to another Form then the Form2 will open successfully but previous Form (Form1) also open in the background).
Pls suggest me what should I do?
regards
Praveen
|
|
|
|
|
There are many ways of doing it.
1. Form.Visible = Fale ' this will hide your form in any Visual Basic Version
2. Unload Form ' this is only for VB6. this will unload your form
3. Form.Close()
4. Form.Dispose()
No. 3 & 4 works with VB2005
And ye Use ME insted of form, because sometimes form might give u error.
Post back if u have anymore questions.
Parth Patel
|
|
|
|
|
Hi guys,
Just want to ask anyone who knows how to use a graph in vb.net? i haven't used a component ever since so i'm really new at this.
i have a component in vb.net called Microsoft Chart. i just don't know how to work on it.
if you can tell me a tutorial site, please do. I just badly need it.
or does anybody know any other components that i can use for charting?
i also need some sample codes to study on how to adjust the bargraph stats programmatically. Can you give me?
Hope you guys would help me.
Thank you.
|
|
|
|
|
Hey
You may want to look at simpler components first, is there no documentation on your chart component on www.msdn.com?
Maybe try some general VB tutorials first http://www.homeandlearn.co.uk/NET/vbNet.html - my apologies if these seem too simple but I dont know what standard you are at. Also try amazon for books on VB.NET - better to walk before you run.
Dan
|
|
|
|
|
ok, I'll take your advice.
Thank you so much..
|
|
|
|
|
|
I have an owner-owned pair of forms and I'd like to raise events from one to the other. I can't seem to find it in the big tome I use. Any ideas?
Richard H.
|
|
|
|