Login to TechLifeForum X
Board Index Go to Reboot.Pro
  • Account Login
  • Register
TechLifeForum
  • Home
  • Members
  • Awards
  • Rules
  • Help
  • Donate
  • Live IRC
TechLifeForum / Programming and Development / .Net Framework Programming v
« Previous 1 ... 16 17 18 19 20 ... 45 Next »
/  Stuck with String Array[Advanced Search]
1 2 Next »
Reply to thread
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

[VB.Net] Stuck with String Array

06-18-2012, 03:00 PM (This post was last modified: 06-18-2012 03:02 PM by Fragma.)
Post: #1
Fragma Offline
Junior Member
**
Posts: 28
Joined: Dec 2011
Reputation: 0
Stuck with String Array
This has been rattling my brain for the past hour or so now so I thought I'd post here for some help.

Basically, I want it so that whenever a user hits the "add" button, the string they entered is added to an array. I want to be able to then loop through each of the strings in the array in a separate sub.

Here's what I have so far:

Public variable for array:
Code: (SELECT ALL CODE)
Dim IDS() As String

Add button:
Code: (SELECT ALL CODE)
othID = webClient.DownloadString("http://www.youtube-mp3.org/api/itemInfo/?video_id=" + getID())            
Dim int1 As Integer = urlList.Items.Count + 1            
Dim int2 As Integer = urlList.Items.Count            
Dim title As String = int1.ToString & ". " & othID.Split(Chr(34))(3)
            If urlList.Items.Count < 20 Then
                urlList.Items.Add(title)                
                IDS(int2) = getID()
            Else                
MsgBox("You have reached the 20 URL limit")            
End If

Download button:
Code: (SELECT ALL CODE)
For Each value As String In IDS                
If value.Length > 0 Then
                    othID = webClient.DownloadString("http://www.youtube-mp3.org/api/itemInfo/?video_id=" + value)                    
title = othID.Split(Chr(34))(3)                  
finID = othID.Split(Chr(34))(35)                    
download = ("http://www.youtube-mp3.org/get?video_id=" & value & "&h=" & finID)
                    dest = Application.StartupPath & "\Downloads\" & title & ".mp3"                    
webClient.DownloadFileAsync(New Uri(download), dest)                    
MessageBox.Show("Please check your application start up directory." & Chr(13) _                                  
& "File successfully downloaded into your ""Downloads"" folder")                
End If
Next

I know that I can add a number to the array like so: "Dim IDS(20) As String", however the problem is, there isn't a set number of strings for the array to hold, I just want it to hold however many items are in the urlList when the user clicks download. I can't figure out how to do this since the array is a public variable.

Hopefully this all made sense. Any help would be greatly appreciated, thanks.
Find
Reply
06-18-2012, 03:31 PM
Post: #2
Xavy01 Offline
ლ(ಠ▿ಠლ)
**
Posts: 54
Joined: Jun 2012
Reputation: 3
RE: Stuck with String Array
I don't completely understand what you are trying to do still, but could using ReDim help?

http://msdn.microsoft.com/en-us/library/...s.80).aspx

Find
Reply
06-18-2012, 03:41 PM
Post: #3
KoBE Offline
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,156
Joined: Jun 2011
Reputation: 47
RE: Stuck with String Array
ReDim would work, but for something like this.. I think using a list would be a better option. Review this sample code to give you an idea. If you would like a better explanation, just let me know.

Code: (SELECT ALL CODE)
Dim lstIDs As New List(Of String)
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        lstIDs.Add("String1")
        lstIDs.Add("String2")

        For Each s As String In lstIDs
            MessageBox.Show(s)
        Next
End Sub

-> TechLifeForum on Facebook<- 
-> TechLifeForum on YouTube<-
-> TechLifeForum on Twitter<-

Tech.Reboot.Pro
WWW Find
Reply
06-18-2012, 03:49 PM
Post: #4
Fragma Offline
Junior Member
**
Posts: 28
Joined: Dec 2011
Reputation: 0
RE: Stuck with String Array
(06-18-2012 03:41 PM)KoBE Wrote:  ReDim would work, but for something like this.. I think using a list would be a better option. Review this sample code to give you an idea. If you would like a better explanation, just let me know.

Code: (SELECT ALL CODE)
Dim lstIDs As New List(Of String)
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
        lstIDs.Add("String1")
        lstIDs.Add("String2")

        For Each s As String In lstIDs
            MessageBox.Show(s)
        Next
End Sub
You're a legend thank you so much. I didn't even know you could do that.
Find
Reply
06-18-2012, 07:47 PM
Post: #5
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,613
Joined: Jun 2011
Reputation: 60
RE: Stuck with String Array
ReDim is slow though, as KoBE shown you why wouldn't you just use a List(of String)?



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
06-19-2012, 08:50 AM
Post: #6
Fragma Offline
Junior Member
**
Posts: 28
Joined: Dec 2011
Reputation: 0
RE: Stuck with String Array
(06-18-2012 07:47 PM)AceInfinity Wrote:  ReDim is slow though, as KoBE shown you why wouldn't you just use a List(of String)?
I did lol... Read my post above.
Find
Reply
06-19-2012, 07:48 PM
Post: #7
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,613
Joined: Jun 2011
Reputation: 60
RE: Stuck with String Array
I read all your posts, just saying, or you didn't know about List(of String) at the time? Or perhaps Redim?



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
06-20-2012, 07:55 AM
Post: #8
Fragma Offline
Junior Member
**
Posts: 28
Joined: Dec 2011
Reputation: 0
RE: Stuck with String Array
Yeh I didn't know of either of those methods when posting the thread. I've always just used what I was before hand. :P

I'll probably be a little more active here now since I'm trying to get back into coding.
Find
Reply
06-20-2012, 08:55 AM (This post was last modified: 06-20-2012 08:56 AM by KoBE.)
Post: #9
KoBE Offline
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,156
Joined: Jun 2011
Reputation: 47
RE: Stuck with String Array
(06-20-2012 07:55 AM)Fragma Wrote:  Yeh I didn't know of either of those methods when posting the thread. I've always just used what I was before hand. :P

I'll probably be a little more active here now since I'm trying to get back into coding.
Both Thumbs Up Why did you ever stop coding..? :P

Edit: Wow, I decided to go see how SF's coding section was doing... :\ Yikes.

-> TechLifeForum on Facebook<- 
-> TechLifeForum on YouTube<-
-> TechLifeForum on Twitter<-

Tech.Reboot.Pro
WWW Find
Reply
06-20-2012, 09:02 AM
Post: #10
Fragma Offline
Junior Member
**
Posts: 28
Joined: Dec 2011
Reputation: 0
RE: Stuck with String Array
(06-20-2012 08:55 AM)KoBE Wrote:  
(06-20-2012 07:55 AM)Fragma Wrote:  Yeh I didn't know of either of those methods when posting the thread. I've always just used what I was before hand. :P

I'll probably be a little more active here now since I'm trying to get back into coding.
Both Thumbs Up Why did you ever stop coding..? :P

Edit: Wow, I decided to go see how SF's coding section was doing... :\ Yikes.
I didn't have time for it. I don't take it seriously enough to do all of the time, it's just a hobby.
Most of my time is spent making animations, illustrations and web graphics.
But it does feel good to get back into the swing of things, even if I rarely ever finish a program lol.
And yeh, SF is near dead now. I haven't posted on there since the thread I made about Breshie's ban. Omni doesn't give a damn about that place so why should the members?? Wink2
Find
Reply
1 2 Next »
Reply to thread


Possibly Related Threads...

Thread: Author Replies: Views: Last Post
   String Format ! Omegastarscream15 5 167 04-05-2013 04:52 PM
Last Post: AceInfinity
   IF statement vs array ? william7 7 279 03-17-2013 01:54 AM
Last Post: AceInfinity
   How do you convert date to string and format it for short version "d"? william7 14 383 03-05-2013 12:15 AM
Last Post: AceInfinity
   MY String Encoding Example AceInfinity 1 171 01-18-2013 12:23 PM
Last Post: AceInfinity
   [Tutorial] Draw a Rotating String [GDI] ThePrinCe 3 298 12-03-2012 04:16 PM
Last Post: Epixors

  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


Users browsing this thread
1 Guest(s)
Youtube Facebook Twitter Digg
Return to Top
All content © copyright TechLifeForum
Powered By MyBB, © 2002-2013 MyBB Group
Designed by ThemeFreak
Mobile Version