Results 1 to 9 of 9

Thread: Couple O' Tricky Questions.

  1. #1
    billfaceuk
    Guest

    Couple O' Tricky Questions.

    Try your hand at these:

    1) I have three buttons on a form. How can I make it that every time the form loads the buttons are in different places???


    2) How can I make a simple search program that searches C:\ and returns the destination of the very first .TXT file it finds.

    Thanx.

  2. #2
    Lively Member Optic's Avatar
    Join Date
    Mar 2001
    Location
    I'm everywhere and nowhere, I'm inside your computer and inside your mind. You can't escape me for I am vision.
    Posts
    117
    for the buttons on form load have it generate 6 numbers assign 1 number to each of the three buttons left and top commands. this will randomly place the buttons. just make sure that it generates a number within the area of the screen.

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148
    This will give you the first txt file on your c:\ drive

    Code:
    Private Sub Command1_Click()
    
    Dim strTxtFile As String
    
      strTxtFile = Dir("C:\*.txt")
      
    End Sub



    ADO, SQL, Access, HTML, ASP, XML
    Visual Basic 6.0 SP5 Enterprise Edition
    VB.Net


  4. #4
    Matthew Gates
    Guest
    Q1:

    Try something like this:

    VB Code:
    1. Private Sub Form_Load()
    2.     Me.WindowState = vbMaximized
    3. End Sub
    4.  
    5. Private Sub Form_Resize()
    6.  
    7.     For Each ctl In Me.Controls
    8.         If ctl = CommandButton Then
    9.             Randomize Timer
    10.             ctl.Move Int(Rnd * Me.ScaleWidth), Int(Rnd * Me.ScaleHeight)
    11.         End If
    12.     Next
    13.  
    14. End Sub

  5. #5
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    How about This:

    A modified version of your 1st question:

    1) With One button on your form, Everytime the form loads, the
    form appears in a different spot on the screen, but the button
    always stays in the same spot on your screen.



    -And by the way, if a .txt file exists per spec of question 2, then
    its destination by def is the c:\, so the answer is:

    [/code]
    Private Sub Command1_Click()
    DoIExist = Dir("c:\*.txt", vbNormal)
    If DoIExist <> "" Then
    MsgBox "c:\"
    Else
    MsgBox "Does Not Exist"
    End If
    End Sub
    [/code]

    -Lou

  6. #6
    billfaceuk
    Guest
    Thanx but is it possible to also search through all the subdirectories as well, for question 2?

  7. #7
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Certainly!

    However, I'm stingy today, so I won't load the code.
    But, I'll give you some suggestions and hints.

    There are many different ways to accomplish what you ask.
    The most sophisticated involve useing api functions, which for
    dir/file searches is in my opinion, a little bit of an overkill.
    However, it certainly crunches the num of code lines down.

    You could go the way of using the Microsoft Scripting Runtime
    Reference and its various functions, which is extremely
    versatile and powerful. However, I've seen it be extremely
    taxing on my systems when I've done massive dir/file operations.
    For File Repository Maintenance involving thousands of large files and directories, it simplifies file monitering, and automation of renaming, moveing, and databasing of file specs. But for you,
    again, this could be overkill.

    Now, there is the simple Dir command. This is the one that I would
    recommend, especially for this exercise, since it seems you haven't gotten the full usage out of it yet. So, How to do it?

    For a Brute force method, consider the following:

    Two Textboxes, one to store found dir's, and one to store
    *.txt files discovered in those directories.

    One command button, to start it up.

    Two functions.

    One to return all directories resident in a passed path, placeing the dir's into one of the boxes.

    Another to perform a *.txt search on a passed path, placeing
    those files into another of the boxes.

    Now, how to Loop?

    First, Clear the boxes. Then Pass "c:\" to both functions.
    Once thats done,
    do a while on the dir listcount <> 0, and loop thru each entry in the dir list box, last to first, passing them to each function. After a path has been passed to both, remove it, so you won't reprocess it again. Go thru the whole text box this way, and keep wending
    until the textbox listcount is zero.

    Now, Since you only want the "First" .txt file, throw in a check on your txt listbox, and when the count > 1, STOP!.

    Then msgbox the first entry.

    Simple.

    -Lou

  8. #8
    Tygur
    Guest
    Originally posted by NotLKH
    How about This:

    A modified version of your 1st question:

    1) With One button on your form, Everytime the form loads, the
    form appears in a different spot on the screen, but the button
    always stays in the same spot on your screen.
    I modified your request a bit. When the form loads, drag it around. The button will stay in the same place on the screen. This was very easy to do. The form is attached.
    Attached Files Attached Files

  9. #9
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Tygur,

    Good Job!

    Don't those API's come in Handy!

    I wish we had a Challenge or Competition area somewhere here.

    As it is, I'll give you 100 VBW Points, good Anywhere in these
    forums.



    (Opps, Gotta write this down,,,
    Tygur : Credit 100 vbw points, total: 100 vbw Points
    Good, Gotit, done!)




    -See Ya
    -Lou

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