Welcome to Dream.In.Code
Become a VB Expert!

Join 137,234 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,681 people online right now. Registration is fast and FREE... Join Now!




Need help with a function

 
Reply to this topicStart new topic

Need help with a function

jloren1
19 Mar, 2007 - 03:01 PM
Post #1

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions
CODE
    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        Dim intCount As Integer
        Dim decSales As Decimal
        Dim strInput As String

        intCount = 1

        Do While intCount <= 5
            strInput = InputBox("Enter today's sales for Store " & intCount.ToString, "Today's Sales")
            If strInput <> "" Then
                If IsNumeric(strInput) Then
                    decSales = CDec(strInput)
                    intCount += 1
                    lstOutput.Items.Add(Store(decSales))
                Else
                    MessageBox.Show("Please enter a valid number for the sales amount.", "Error")
                End If
            Else
                Exit Do
            End If
        Loop


    End Sub


    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
    Function Store(ByVal decSales As Decimal)

    End Function


Hi, I'm having some trouble with this homework problem. I've gotten the first part but I'm lost on the next
The problem is: Write a program that asks user to enter today’s sales for five stores. The program should then display a bar graph comparing each store’s sales. Create each bar in the bar graph by displaying a row of asterisks in a listbox. Each asterisk should represent $100 of sales. The prompt should be in a loop. Also, create and call a funciton to return a string of asterisks. Pass the sales amount to the function. I'm unsure of how to write a function to return asterisks. Also, I'm using VB 05 express edition. Anyone able to point me in the right direction on how to go about writing the function?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Need Help With A Function
19 Mar, 2007 - 04:06 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You will simply return a String object that contains "*****".
CODE
Dim astString As String

'some code here that determines how many astericks and starts a loop
astString = astString & "*"


return astString

User is online!Profile CardPM
+Quote Post

jloren1
RE: Need Help With A Function
19 Mar, 2007 - 04:15 PM
Post #3

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions
My fault on not stating exactly my problem. I'm having a problem coming up with the loop that determines how many asterisks will be returned. My best guess right now is that it is a Do...Until Loop but beyond that I'm lost.

This post has been edited by jloren1: 19 Mar, 2007 - 04:20 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Need Help With A Function
19 Mar, 2007 - 04:46 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Per your assignment you can determine the number of asterisks by taking the a stores sales and divide by 100. The result of the calculation is the number of times you need to loop adding one asterisk to the string at a time.

Since you know specifically how many times to loop from your calculation the best loop to use would be a FOR loop.

Example:
CODE

loopCount = storeSales / 100

for x = 1 to loopCount
   astString = astString & "*"
Next x

User is online!Profile CardPM
+Quote Post

jloren1
RE: Need Help With A Function
19 Mar, 2007 - 04:56 PM
Post #5

New D.I.C Head
*

Joined: 19 Mar, 2007
Posts: 3


My Contributions
I got it to work now. Thank you for your help.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:57PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month