Results 1 to 9 of 9

Thread: Array problems

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2020
    Posts
    17

    Array problems

    Why can't i get this array to save data?

    frmRecursion.zip

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Oct 2020
    Posts
    17

    Re: Array problems

    i guess i forgot to use Preserve.

    ReDim Preserve sArr()

    Now it works.
    Last edited by Tert; Jul 7th, 2021 at 11:49 AM.

  3. #3
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: Array problems

    Remember, people that help others on this site are doing this for free, spending their own time that they could be using to do other things.

    For me, and I'm assuming others on this site as well, the more hoops I have to jump through just to try to understand what the question/problem is, I am exponentially less likely to take any of my time to try to help that person out.

    In this case, anyone wanting to help you would need to download and extract the zip file, load your code file(s) (of which there could be many), try to scan through your code (which could be voluminous) just to try to identify the code that you MIGHT be asking about.

    For me personally, and presumably others on this site, I never download any attachments posted by users here. There's just too many vulnerabilities floating around these days in just about everything that it just isn't worth it. So, right off the bat, you are greatly reducing the number of potential people here willing to try to help you by simply dropping a zip file in a thread and basically saying "help".

    I'm taking the time to post this for you, not to be a dick, but to try to help you to understand that you should probably do at least two things if you want the largest potential audience of those willing to help you:

    1. Explain what, exactly, you want your code to be able to do. For example, you say you want to save data. In a database? In a data file? In the registry?

    2. Post only the relevant code into the thread as text (enclosing it in Code tags to make the formatting readable)

    Good luck.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2020
    Posts
    17

    Re: Array problems

    Recursion using API?
    Still get some issue with the array items though


    Here's the code

    Code:
    Option Explicit
    
    Private Const vbDot = 46
    Private Const MAX_PATH As Long = 260
    Private Const INVALID_HANDLE_VALUE = -1
    Private Const vbBackslash = "\"
    Private Const ALL_FILES = "*.*"
    
    Private Type FILETIME
       dwLowDateTime As Long
       dwHighDateTime As Long
    End Type
    
    Private Type WIN32_FIND_DATA
       dwFileAttributes As Long
       ftCreationTime As FILETIME
       ftLastAccessTime As FILETIME
       ftLastWriteTime As FILETIME
       nFileSizeHigh As Long
       nFileSizeLow As Long
       dwReserved0 As Long
       dwReserved1 As Long
       cFileName As String * MAX_PATH
       cAlternate As String * 14
    End Type
    
    Private Type FILE_PARAMS
       bRecurse As Boolean
       nCount As Long
       nSearched As Long
       sFileNameExt As String
       sFileRoot As String
    End Type
    
    Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal lpString As Long) As Long
    Private Declare Function PathMatchSpec Lib "shlwapi" Alias "PathMatchSpecW" (ByVal pszFileParam As Long, ByVal pszSpec As Long) As Long
    
    Private fp As FILE_PARAMS  'holds search parameters
    
    Private sArr() As String
    Dim iArrCnt As Integer
    
    Private Sub Command1_Click()
       Dim tstart As Single   'timer var for this routine only
       Dim tend As Single     'timer var for this routine only
       Text3.Text = ""
       Text4.Text = ""
       Text5.Text = ""
       Screen.MousePointer = 11
       Refresh
       With fp
          .sFileRoot = QualifyPath(Text1.Text) 'start path
          .sFileNameExt = Text2.Text           'file type(s) of interest
          .bRecurse = Check1.Value = 1         'True = recursive search
          .nCount = 0                          'results
          .nSearched = 0                       'results
       End With
       tstart = GetTickCount()
        iArrCnt = -1
        Call SearchForFiles(fp.sFileRoot)
       tend = GetTickCount()
       Screen.MousePointer = 0
       Text6.Text = Join(sArr(), vbNewLine)
       Text3.Text = Format$(fp.nSearched, "###,###,###,##0")
       Text4.Text = Format$(fp.nCount, "###,###,###,##0")
       Text5.Text = FormatNumber((tend - tstart) / 1000, 2) & "  seconds"
    End Sub
    
    Private Sub SearchForFiles(sRoot As String)
       Dim WFD As WIN32_FIND_DATA
       Dim hFile As Long
       hFile = FindFirstFile(sRoot & ALL_FILES, WFD)
       If hFile <> INVALID_HANDLE_VALUE Then
          Do
            'if a folder, and recurse specified, call method again
             If WFD.dwFileAttributes And vbDirectory Then
                If Asc(WFD.cFileName) <> vbDot Then
                 fp.nCount = fp.nCount + 1: iArrCnt = iArrCnt + 1: ReDim Preserve sArr(iArrCnt) As String
                 sArr(iArrCnt) = sRoot & TrimNull(WFD.cFileName) & vbBackslash & vbTab & FileDateTime(sRoot & TrimNull(WFD.cFileName))
                 If fp.bRecurse Then SearchForFiles sRoot$ & TrimNull(WFD.cFileName) & vbBackslash
                End If
             Else
               'must be a file..
                If MatchSpec(WFD.cFileName, fp.sFileNameExt) Then
                   fp.nCount = fp.nCount + 1: iArrCnt = iArrCnt + 1: ReDim Preserve sArr(iArrCnt) As String
                   sArr(iArrCnt) = sRoot & vbTab & TrimNull(WFD.cFileName) & vbTab & FileDateTime(sRoot & TrimNull(WFD.cFileName))
                End If
             End If
             fp.nSearched = fp.nSearched + 1
          Loop While FindNextFile(hFile, WFD)
       End If
       Call FindClose(hFile)
    End Sub
    
    Private Function QualifyPath(sPath As String) As String
       If Right$(sPath, 1) <> vbBackslash Then
          QualifyPath = sPath & vbBackslash
       Else
          QualifyPath = sPath
       End If
    End Function
    
    Private Function TrimNull(startstr As String) As String
       TrimNull = Left$(startstr, lstrlen(StrPtr(startstr)))
    End Function
    
    Private Function MatchSpec(sFile As String, sSpec As String) As Boolean
       MatchSpec = PathMatchSpec(StrPtr(sFile), StrPtr(sSpec))
    End Function
    Last edited by Tert; Jul 7th, 2021 at 11:43 AM.

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Array problems

    Quote Originally Posted by OptionBase1 View Post
    Remember, people that help others on this site are doing this for free, spending their own time that they could be using to do other things.

    For me, and I'm assuming others on this site as well, the more hoops I have to jump through just to try to understand what the question/problem is, I am exponentially less likely to take any of my time to try to help that person out.

    In this case, anyone wanting to help you would need to download and extract the zip file, load your code file(s) (of which there could be many), try to scan through your code (which could be voluminous) just to try to identify the code that you MIGHT be asking about.

    For me personally, and presumably others on this site, I never download any attachments posted by users here. There's just too many vulnerabilities floating around these days in just about everything that it just isn't worth it. So, right off the bat, you are greatly reducing the number of potential people here willing to try to help you by simply dropping a zip file in a thread and basically saying "help".

    I'm taking the time to post this for you, not to be a dick, but to try to help you to understand that you should probably do at least two things if you want the largest potential audience of those willing to help you:

    1. Explain what, exactly, you want your code to be able to do. For example, you say you want to save data. In a database? In a data file? In the registry?

    2. Post only the relevant code into the thread as text (enclosing it in Code tags to make the formatting readable)

    Good luck.
    What he said. I clicked on your post and when I saw one line question and an attachment I wasn't going any further.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2020
    Posts
    17

    Lightbulb Re: Array problems

    Yea maybe

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Array problems

    Quote Originally Posted by Tert View Post
    Still get some issue with the array items though
    Like what? Have you tried removing eels from your hovercraft? That sometimes works.
    If not, there's a guide in my signature block on how to do that. Click. Read. Be enlightened and try again.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2020
    Posts
    17

    Re: Array problems

    this eel/hovercraft post of yours is not sticky thread and yet it may be useful for some while I like others may be happier seeing less info whenever possible and provided this threat says recursion and that it has an array problem perhaps the issues brought up about not having any trust in downloading attachments or not having enough info without any other questions might be too much info. If the problem stands where textbox doesn't display all the data with arrays that part is not the real issue as I seemed to solve the problem with Preserve for arrays so thanks and appreciate all your posting. Good deal
    hey by the way if the post doesn't conform to site standards then kindly let everyone know but we can't be the blind leading the blind if we know how to code and don't mind seeing what others are doing.
    Last edited by Tert; Jul 7th, 2021 at 11:51 AM.

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Array problems

    Less info, or rather almost no info is rarely a bonus. Very little info followed by a link or large block of code is also rarely a good thing. At minimum any question should have enough detail that it is clear to would be helpers what the problem is.

    For example
    Still get some issue with the array items though
    Followed by a sizable block of code. The statement could mean almost anything and anyone who would want to help would have to study the code just to try and see what problem the user may be having. This would of course take more of each and every would be helpers time than it would have taken the questioner to have simply written a couple more lines to state the specific nature of what "some issue" actually is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width