LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-19-2003, 11:45 AM   #1
libster
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Rep: Reputation: 0
quick noob visual basic question


Im learning visual basic and hopefully someone will be able to help out. I did the first part of the question now can someone please help me out with 1b

Task1: Make a program that will print a triangle of stars. User must be able to input amount of stars on bottom row.

"
Public Sub Main()
Dim Counter As Integer
Dim NumOfStars As Integer
Dim Stars As String

Stars = "*"

NumOfStars = InputBox("Please input number of stars on bottom row:")

For Counter = 1 To NumOfStars
Debug.Print Stars; ""
Stars = Stars + "*"
Next Counter

End Sub
"

Task1b: Do the same as above except opposite way around i.e upside down triangle. answer should look something like this


*****
****
***
**
*

and this is how i tryed to answer the question even though i did it wrong

"
Public Sub Main()

Dim Counter As Integer
Dim NumOfStars As Integer
Dim Stars As String

NumOfStars = InputBox("Please input number of stars on top row:")
Stars = "*"

For Counter = NumOfStars To 1 Step -1
Debug.Print Stars; ""
Stars = Stars - "*"
Next Counter

End Sub
"

anyone know the answer to the question 1b?
thanks
 
Old 10-19-2003, 11:55 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
2 things:

1. This is a Linux site. VB is a Microsoft product - non-Linux.
2. The Rules that you agreed to state that we don't answer homework questions.

May I suggest that you either read up on the problem or ask on a Microsoft site?
 
Old 10-19-2003, 12:37 PM   #3
libster
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by XavierP
2 things:

1. This is a Linux site. VB is a Microsoft product - non-Linux.
2. The Rules that you agreed to state that we don't answer homework questions.

May I suggest that you either read up on the problem or ask on a Microsoft site?
1. "This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game." - It says any language is fair game that includes visual basic, it doesnt matter if its a microsoft product or am I wrong?

2. Actually I have done my homework, and this is not it. These are extra questions I looked up in my book so I could practise and learn more about Basic. Maybe I should have rephrased my question so that it looked like I was working on a project, then maybe I would have got more help. Either way I dont see why it should matter since in both cases all Im trying to do is learn. All I wanted was a point in the right direction.

3.Maybe I should have posted in a Microsoft Forum but since Ive found (in most cases) these forums to be faster and more friendly I decided to post here.
 
Old 10-19-2003, 12:54 PM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Lubuntu
Posts: 19,176
Blog Entries: 4

Rep: Reputation: 430Reputation: 430Reputation: 430Reputation: 430Reputation: 430
Well, yes, it does matter that this is a Linux site. Although a number of people here can and do program in VisualBasic, that is a Windows program and most of us will have to reboot to get back into Windows.

There are likely to be more VB programmers on an MS VB newsgroup/forum.

Apologies if I came down a little hard - but it did look just like a homework question.....
 
Old 10-19-2003, 03:53 PM   #5
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
well i'm not in windows to test this out, but maybe something like this:

Code:
stars = "******"
txtMultilineTextbox.Text = ""
for i = 0 to (len(stars) - 1)
	txtMultilineTexBox.text = txtMultilineTextBox.txt & _
			left (stars, len (stars) - i) & vbcrlf
next i

Last edited by megaspaz; 10-19-2003 at 05:55 PM.
 
Old 10-20-2003, 01:34 AM   #6
JesterXXV
LQ Newbie
 
Registered: Jun 2003
Distribution: Slackware 9.1
Posts: 7

Rep: Reputation: 0
first off, the line Stars = "*" is wrong. It should be something like Stars = String$(NumOfStars, "*") (the parameters might need to be flipped around).

Also, the line in your loop Stars = Stars - "*" won't work, afaik. The - operator just doesn't work that way with strings, because what if the string didn't have any *'s in it, or didn't have one at the end? Anyway, do it kinda like megaspaz suggested: Stars = Left (Stars, len(Stars) - 1). Hopefully you can understand why.

Simple question, simple answer, and I didn't even need to reboot to get back into Windows.
 
Old 10-20-2003, 02:29 PM   #7
libster
LQ Newbie
 
Registered: Feb 2003
Posts: 6

Original Poster
Rep: Reputation: 0
I managed to get it working, here's what i did

Public Sub Main()
Dim Counter As Integer
Dim NumOfStars As Integer
Dim Stars As String

NumOfStars = InputBox("Please input number of stars on top row:")
Stars = "*"

Do Until NumOfStars = "0"
Do Until Len(Stars) = NumOfStars
Stars = Stars + "*"
Loop
Debug.Print Stars; ""
NumOfStars = NumOfStars - 1
Stars = "*"
Loop
End Sub

Thanks for the help.
 
Old 10-20-2003, 08:31 PM   #8
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
just a comment. you're code is how shall we say it.... bloated and inefficient? you wrote about 3x's as many lines of code than necessary in a nested loop, when you could've written it in 3-4 lines in a single loop by just learning about the left, mid, and right functions.

edit:
figured you might want to see some code. this code has some pre-emptive checking.
Code:
Option Explicit

Private Const mlngMaxSize As Long = 15


Private Sub cmdGen_Click()
    Dim strStars As String
    Dim lngI As Long
    Dim lngJ As Long

    ' initialize and verify block
    lngI = mlngMaxSize
    If IsNumeric(txtIn.Text) = True Then
        lngI = Val(txtIn.Text)
    End If
    ' display number of stars
    txtIn.Text = lngI

    txtOut.Text = ""

    ' actual do stuff code - 3 lines of code starting at loop. 
    ' yours is 9 lines of code starting at your loop
    strStars = String$(lngI, "*")
    For lngJ = 0 To (Len(strStars) - 1)
        txtOut.Text = txtOut.Text & _
		Left(strStars, Len(strStars) - lngJ) & vbCrLf
    Next lngJ
End Sub
Form Screenshot

Last edited by megaspaz; 10-20-2003 at 09:33 PM.
 
Old 10-29-2003, 08:52 AM   #9
|DC|Cid
LQ Newbie
 
Registered: Oct 2003
Posts: 6

Rep: Reputation: 0
If you have VB questions try www.vbforums.com
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stupid Question: Microsoft Visual Studio 6.0 (A.K.A. Visual Basic 6) Will it run? S0RD3N Linux - Software 8 05-07-2008 08:42 PM
Visual Basic.net Question Ryan450 Programming 1 05-20-2005 12:31 PM
Please Help A Noob, Quick Question About Dual Boot JacobRV Linux - Newbie 6 11-18-2004 10:35 PM
Quick Noob question zidane2010 Linux - General 2 02-18-2004 07:42 PM
Quick Easy Basic Question RaheimSG Linux - Hardware 5 09-12-2002 07:00 AM


All times are GMT -5. The time now is 11:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration