ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.....
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.
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.
figured you might want to see some code. this code has some pre-emptive checking.
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)
' 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