# Visual Logic Chapter 4 Problem 4



## drury20 (Jul 1, 2012)

Write a program that uses a nested loop to generate the output shown below. Be sure that the value on the line changes with each digit displayed. For example, line 5 has the values 1 2 3 4 5.

1
12
123
1234
12345
123456
1234567
12345678
123456789

I'm sure it is something simple that I am overlooking but any help is greatly appreciated. Thanks.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

In pseudocode it would look something like:

```
for i = 1 to 9 
   for j = 1 to i
      print j
   end for j
   next line
end for i
```


----------



## AceInfinity (Jan 21, 2012)

```
Private Sub WriteStuff(NumberOfLines As Integer)
	For i As Integer = 1 To NumberOfLines
		Console.WriteLine(String.Concat(Enumerable.Range(1, i)))
	Next
End Sub
```
Try that. Replace Console.WriteLine with where you want to write the value.


```
WriteStuff(9)
```


----------



## drury20 (Jul 1, 2012)

Thanks for the help guys!
I have another problem that I am having trouble with in the next chapter.

Target Value

Write a program that accepts ten input values and stores them in an array. After reading the ten values, the program should then input one more value which is called the target value. The program should then search through the array to calculate and display how many times the target value appears inside the array.

Any help is appreciated.


----------



## AceInfinity (Jan 21, 2012)

I'm not doing your homework for you, just to make things clear here. I'm a straightforward guy so i'll be completely honest here. So some hints:

1) *"Write a program that accepts ten input values and stores them in an array"* - Create an array with it's number of elements set to 10 as it is declared/initialized. That way we have a placeholder waiting for us, for 10 array elements.

2) *"the program should then input one more value which is called the target value"* - Take the target value in as a regular variable. I'm assuming these are all going to be string objects as each input... Same principle would apply to the logic with other types though, and comparing.

3) *"should then search through the array to calculate and display how many times the target value appears inside the array"* - Use a For loop, i'd recommend For Each, but since we know the number of items you could do the For i As Integer = 0 To 9 loop, each iteration with i being the 0-based index of the array we want to check through.

Declare an Integer above the loop code, as a variable initialized to 0 to start, and for each loop, compare array index to the value of our target variable. If it's the same, increment the counter by one... After the looping is done with, then display the counter's finalized value.


----------



## drury20 (Jul 1, 2012)

Thank you again for the help with the 2 problems that I submitted. I am still having trouble with the second problem (Target Value). I have included a screenshot of what I have but there is an error in evaluating the condition. Insight on what I have done wrong? I am not asking for an answer to the problem, just some direction as to what I have done wrong. Thank you.


----------



## AlbertMC2 (Jul 15, 2010)

Hi

Your logic is fine.
If I create your program on my Visual Logic system then it works perfectly.
What error are you getting and where are you getting it?

To discover where the program is getting stuck put Output commands at various stages in your program especially in the FOR and IF loops. This way you will be able to see what the last command is that ran and which command is failing.


----------



## drury20 (Jul 1, 2012)

The error statement is this...."Error in Evaluating Condition Expression"
"ERROR: Invalid assignment in command "TargetValue = List(M)"

I don't know what is going wrong, especially if you are getting the exact same thing to work.


----------



## AlbertMC2 (Jul 15, 2010)

Just before the "TargetValue = List(M)" create one output for "TargetValue" and another for "List(M)" just to see if these variables are outputting the correct values that you entered.


----------



## drury20 (Jul 1, 2012)

Nope, it will not output either the TargetValue or List(M). I just am not getting what I am doing wrong here. It seems like with what I have it should work fine. Any other suggestions? Thanks again.


----------



## AlbertMC2 (Jul 15, 2010)

You are outputting them BEFORE the IF condition?
You can also try ouputting them after you have entered the variables:
So *output List(M)* just after *Input: List(M)*
and *Output TargetValue* just after *Input: TargetValue*

Also it might be nothing but just above your Input and Output boxes there is a little white box which mine does not have. Do you know what it is?


----------



## Zombette (Mar 19, 2013)

drury20 said:


> Thank you again for the help with the 2 problems that I submitted. I am still having trouble with the second problem (Target Value). I have included a screenshot of what I have but there is an error in evaluating the condition. Insight on what I have done wrong? I am not asking for an answer to the problem, just some direction as to what I have done wrong. Thank you.
> View attachment 114207


I know this thread is old, but I stumbled upon it because I'm taking a VL course right now. 
The problem with the program above is in the Array. You have it as Make Array(List, 11) when it needs to be Make Array(List, 10).
My program is this way and it works perfectly 

Just for anyone else who stumbles upon this thread ^^


----------



## AlbertMC2 (Jul 15, 2010)

This should not make a difference.
When the array is declared it declares 11 items. (Make Array(List, 11))
However when items are entered into the array only 10 items are entered (M 1 to 10)
and when searching only the 1st 10 items are searched (once again M 1 to 10)


----------

