-1

Based on How can I declare a two dimensional string array? I've made my own array but am struggling to retrieve the values.

I get a syntax error which appears to relate to the second (0) line (0) = (((1) / total) * (100 - (vPercentChanger))) but the error might occur on the line above this (see code below).

Error: Syntax error. Code:

  'Test values
Dim highPer As Double = 5
Dim high As Double = 10
Dim medPer As Double = 15
Dim medium As Double = 20
Dim lowPer As Double = 1
Dim low As Double = 2
Dim naPer As Double = 3
Dim na As Double = 4

Dim array1 As Double(,) = New Double(3, 1) {{highPer, high}, {medPer, medium}, {lowPer, low}, {naPer, na}}

Dim tmpList As New List(Of Double)
For i As Integer = 0 To array1.Rank - 1
If (0) > 5 + vPercentChanger Then
                (0) = (((1) / total) * (100 - (vPercentChanger)))     
End If

Next

Further notes:

I've tried array1(0) and tmpList(0) but both create errors. I believe I am close. I've tried the C# to VB converter but this does not resolve this issue.

Community
  • 1
  • 1
indofraiser
  • 1,014
  • 3
  • 18
  • 50

1 Answers1

0

As written, there are a few problems with the code.

We have declared array1 as an array with 3 rows with 1 entry in each but the given data is 4 rows with 2 entries in each.

I afraid that I couldn't understand the Values as strings... note. Unless the highPer, high et al. are variable names, they need quotations marks around them. If they are variable names, the variables should have been included in the example to meet the Minimal, Complete, Verifiable example standards.

You have tried both array1(0) and tmpList(0) - what are you trying to achieve?

array1 is a 2D array so we need to address it with 2 indices, e.g. array1(0,0).

Both tmpList and array1 contain strings, comparing the values with numbers or assigning numbers into them seems wrong (does VB perform some sort of implicit conversion? Are you sure that you want to work with strings, perhaps they should be arrays/lists of numbers?

Update:

From the comments, it looks like we have an array representing a list of pairs

{valPct, val}

and we want to iterate through them and check

 if valPct > (5 + vtPercentChanger) then
     valPct = (val / total) * (100 - vPercentChanger)

We can do this with

dim values as double(,) = {{v1Pct, v1}, {v2Pct, v2}, {v3Pct, v3}}

for index as integer = 0 to values.GetUpperBound(1) -1
    if (values(index,0) > (5 + vtPercentChanger)) then
        values(index,0) = (values(index,1) / total) * (100 - vPercentChanger)
next

This is unfortunately done with no code checking - using phone on bus - but should give the general shape.

Community
  • 1
  • 1
AlanT
  • 3,627
  • 20
  • 28
  • I want to write code once that references the values in a library (variables/values) and do something with them. This library only has four but some might be longer. – indofraiser Jun 16 '16 at 10:30
  • @indofraiser Can you describe what you are trying to do in the loop - at the moment, it is not obvious. You do something for each dimension in `array1` (note - each dimension [2] not each row [4] or each column[2]) and you assign a value to something (not apparent what) based upon values that are not from the array (unless (1) is intended to be an index into the array). Knowing what you are trying to achieve would help direct the answer – AlanT Jun 16 '16 at 10:38
  • Far point. We display a dynamically build sideward bar graph using CSS. If after some maths the percent of the value means the pixel width would be under 5 then we 'boost' this so the user can see it. However if say the value is 1 and is put to 5 the total is now 104 wide (so 104% of a 100% width) so I do some sums to tidy this. This part, as it stands looks like: If highPer > 5 + vPercentChanger Then highPer = ((high / total) * (100 - (vPercentChanger))) – indofraiser Jun 16 '16 at 10:42
  • I hope that makes a bit more sense now, essentially that required two values as one in an actual value and one is a value that's been altered for visual purposes – indofraiser Jun 16 '16 at 10:43
  • More sense. It looks like you shouldn't be using strings, as you want to do calculations. If you reset the code with the original values `highPer` et al. and make it an array of double rather than string and update the question to show the information about what you are trying to achieve it will make it easier for others to answer - people tend to look over the question and if there is not enough information at first glance they may not even look at the comments – AlanT Jun 16 '16 at 10:54
  • I believe I've edited as per notes. Let me know though and thanks – indofraiser Jun 16 '16 at 11:28