Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 131,651 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 3,548 people online right now. Registration is fast and FREE... Join Now!




Plz hlp: Output an array to 2 columns vb.net...

 
Reply to this topicStart new topic

Plz hlp: Output an array to 2 columns vb.net..., Need help: 1 array 2 columns - wht 2 do?

munchkin
post 22 Apr, 2005 - 03:12 AM
Post #1


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


Hey all - Im new and I was wondering if any of you nice coder peeps could help, Im not the best at VB.net in the world and i seem to have come to a stop sad.gif

If you can see - what I want to do is, if there are more than 10 entries in the array (kewordArry) then i want to split the data into 2 Html columns - that part is sorted - but obviously with what i am writing both columns will contain the same information (the full array) - I need the even values to go into the first column and the odd values to go into the second, while if there are less than 10 entries - all values to carry into the column at the bottom.

If any of you nice peeps out there in computer land could help - id appriciate it lots smile.gif

CODE

Function getKeyWords(ByVal str As String, ByVal queryStr As String) As String
       ' function getKeyWords() returns a comma seperated string of keywords
       ' Quirks:
       '   the keywords are extracted from 'str' and any occurrence of a word in
       '   keywords that have been searched for are highlighted.
       '   all keywords provide a link to the search results page
       '   with the specified keyword as the search criteria.

       'Response.Write(str)
       Dim retVal As New String("")
       Dim keywordArryLegnth As New String("")
       Dim i As Integer = 0
       Dim keywordArry() As String = Split(str, ",")

       retVal = ""
       keywordArryLegnth = UBound(keywordArry)

       If UBound(keywordArry) > 10 Then
          'Column 1 - place even Array entries here
           retVal &= "<div id=""products-list-1""><h3>Products &amp; Services</h3><ul>"

           For i = 0 To keywordArry.Length - 1

               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & keywordArry(i) & """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next

           'retVal &= "</ul>" & keywordArryLegnth & "</div>"

           retVal &= "<div id=""products-list-2""><ul>"

           For i = 0 To keywordArry.Length - 1
          'Column 2 - place even Array entries here
               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & keywordArry(i) & """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next
           retVal &= "</ul></div>"

       Else


           retVal &= "<div id=""products-list-1""><h3>Products &amp; Services</h3><ul>"

           For i = 0 To keywordArry.Length - 1
          'Column 1 - place all Array entries here if there are less than 10
               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & keywordArry(i) & """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next

           retVal &= "</ul></div>"

       End If

       Return (retVal)
   End Function



Many thanks



Munchkin smile.gif

This post has been edited by munchkin: 22 Apr, 2005 - 06:05 AM
User is offlineProfile CardPM

Go to the top of the page


Amadeus
post 22 Apr, 2005 - 05:30 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


Well, it looks as if your array is coming in to the function as an array of strings...is that correct? Does the array actually contain numbers? If so, you'll have to convert each element to an Integer as you go (ConverToInt32()), then use the modulus operator to determine odd or even...
CODE

if num Mod 2 = 0 Then
'number is even
else
'number is odd
end if
User is online!Profile CardPM

Go to the top of the page

munchkin
post 22 Apr, 2005 - 05:48 AM
Post #3


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


Thanks for your help...

Hmmm, sorry - ive just re-read what i had written.. The Array carries values like:

(0) accredited quality certification
(1) quality standards qualifications
(2) environmental standards qualifications

alteast 1 and upto 50

and i want half the array values in col 1 and half in col 2, (i thought alternating the values would make it easyer) I have mannaged to get this so far - but I am having troubel when the array legnth is of an odd number now sad.gif

This is how i have modified the code now.. I know Im getting there - but i think that my maths are off and i need to pad the array at the end if Ubound returns an odd number - but as i said - im not 100% sure...

CODE

Function getKeyWords(ByVal str As String, ByVal queryStr As String) As String
       ' function getKeyWords() returns a comma seperated string of keywords
       ' Quirks:
       '   the keywords are extracted from 'str' and any occurrence of a word in
       '   keywords that have been searched for are highlighted.
       '   all keywords provide a link to the search results page
       '   with the specified keyword as the search criteria.

       'Response.Write(str)
       Dim retVal As New String("")
       Dim keywordArryLegnth As New String("")
       Dim keywordArryLegnthHalf As New String("")
       Dim i As Integer = 0
       Dim keywordArry() As String = Split(str, ",")

       retVal = ""
       keywordArryLegnth = (UBound(keywordArry) + 1)
       keywordArryLegnthHalf = ((UBound(keywordArry) + 1) \ 2)

       If UBound(keywordArry) > 10 Then

           retVal &= "<div id=""products-list-1""><h3>Products &amp; Services</h3><ul>"

           For i = 0 To ((UBound(keywordArry) + 1) \ 2)

               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & Trim(keywordArry(i)) &  """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next

           retVal &= "</ul></div>"
           retVal &= "<div id=""products-list-2""><ul>"

           For i = ((UBound(keywordArry) + 1) \ 2) + 1 To keywordArry.Length - 1

               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & Trim(keywordArry(i)) & """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next
           retVal &= "</ul></div>"

       Else


           retVal &= "<div id=""products-list-1""><h3>Products &amp; Services</h3><ul>"

           For i = 0 To keywordArry.Length - 1

               retVal &= "<li><a href=""" & ConfigurationSettings.AppSettings("URL") & "/results/index.aspx?qt=" & Trim(keywordArry(i)) & """>"
               retVal &= highlightSearchTerms(Trim(keywordArry(i)), Request("qt"))
               retVal &= "</a></li>"

           Next

           retVal &= "</ul></div>"

       End If

       Return (retVal)
   End Function


Once again


Thanks in advance

Munchkin

This post has been edited by munchkin: 22 Apr, 2005 - 05:49 AM
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 22 Apr, 2005 - 06:13 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


What problem is ocurring with an array with an odd number of elements? Even or odd number, you can just switch on the counter variable i, if i is even, place the value in one column, if i is odd, place the value in the other.
User is online!Profile CardPM

Go to the top of the page

munchkin
post 22 Apr, 2005 - 06:20 AM
Post #5


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


Well, the problem is that if UBound(keywordarry) brings back an odd value then the keyword where the split for the 2 colums is will not appear, and if it is even then the lists are unbalanced...

How would I switch the counter variable from odd to even?? Or how would i split the list exacticaly in half?

Once again, Than you amadeus for you help

This is muchly apriciated biggrin.gif



Munchkin
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 22 Apr, 2005 - 11:45 AM
Post #6


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


Just to make sure I understand, let's elaborate...

You have an array of strings. If that array of strings has more than 10 items, you want to display half of the array in one column, and the other half in a second column, is that correct?

If that is correct, then you need to
  • get the length of the array
  • if less then 10, display
  • if greater then 10, separate and display
The first part is easy...
CODE

len = array.Length

Then you'll need a conditional statement to fork

CODE

if len < 10
'display the data
else
'we have to split the array into two columns
'code below goes in here
end if

to make the displaying easier, you can even write two new arrays
CODE

Dim arr1(), arr2() as String

With the two new arrays in hand, you can fill them based on the value of the counter being odd or even
CODE

for i = 0 to UBound(array)
  if i Mod 2 = 0 then
     'the index is even
      arr1.Add(array(i))
  else
     'the index is odd
     arr2.Add(array(i))
  end if
next

Now you've got two arrays, or lists, of roughly equal lengths...you can display them at your leisure.
User is online!Profile CardPM

Go to the top of the page

munchkin
post 26 Apr, 2005 - 06:54 AM
Post #7


New D.I.C Head

*
Joined: 22 Apr, 2005
Posts: 21


My Contributions


Thankyou somuch my friend biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 06:26AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month