Announcement

Collapse
No announcement yet.

random file selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • fischb22
    replied
    Code:
    Dim di As DirectoryInfo
    seems to be causing the error, not sure why?!?! i'm importing system.io

    Leave a comment:


  • CFGuy
    replied
    I have only been working in plugins but clsjquery items needs the following

    Imports Scheduler


    but with what you are wanting to do you can remove the dropdown and just use the array.
    PHP Code:
    di = New IO.DirectoryInfo(fullPathway to your directory
    diar1 di.GetFiles() 
    Dim nFiles As Int16 diar1.GetUpperBound(0)
    ' Get your random number.
    Dim filename as string = diar1(rndNumber).ToString 
    That should give you what you said you are wanting. An array of the files. nFiles should give you the number of files in the directory.
    Select a number between 0 and nFiles
    You can then use File.Copy to move the random file.

    Make sure that you replace
    ' Get your random number.
    with some code that gets a random number between 0 and nFiles

    Leave a comment:


  • fischb22
    replied
    errors out....

    Code:
    imports system.io
    
    sub main
        hs.WriteLog "Error", "Hello World"
        sourcedir= "E:\Source\hs3\pics"
    
    Dim di As DirectoryInfo 
    Dim diar1 As FileInfo() 
    Dim dra As FileInfo 
      
    di = New IO.DirectoryInfo(sourcedir) 
    diar1 = di.GetFiles() 
    dd = New clsJQuery.jqDropList(sDdName, pageName, False) 
    dd.AddItem("No Script", "", sSel = "") 
    
    dir_count = 0
    
    For Each dra In diar1 
    If dra.Extension.ToLower = ".png" Or dra.Extension.ToLower = ".jpg" Then 
    dir_count = dir_count + 1
    dd.AddItem(dra.Name, dra.Name, dra.Name = sSel.Trim) 
    End If 
    Next 
    s.Append(dd.Build) 
    
    hs.WriteLog "Error", "Number of files: " & dir_count 
    
    end sub
    error

    Code:
    Expected end of statement in line 7 More info: Expected end of statement

    Leave a comment:


  • CFGuy
    replied
    In the weatherXML plugin I use vb.nets directoryInfo and fileInfo to get a list of all the script files in the HS script directory to build a dropdown.
    PHP Code:
    Dim di As DirectoryInfo
    Dim diar1 
    As FileInfo()
    Dim dra As FileInfo
     
    di 
    = New IO.DirectoryInfo(fullPathway to your directory)
    diar1 di.GetFiles()
    dd = New clsJQuery.jqDropList(sDdNamepageNameFalse)
    dd.AddItem("No Script"""sSel "")
    For 
    Each dra In diar1
    If dra.Extension.ToLower ".vb" Or dra.Extension.ToLower ".txt" Then
    dd
    .AddItem(dra.Namedra.Namedra.Name sSel.Trim)
    End If
    Next
    s
    .Append(dd.Build
    You should be able to modify this and use diar1 as your array.. Once you have a random picture selected you can use File.Copy to copy it to the html directory.

    Leave a comment:


  • fischb22
    started a topic random file selection

    random file selection

    greetings,

    i thought i was a good vb programmer until i tried to write a script in homeseer.

    i just want to grab an array of the files in a given directory, select one at random and copy it to the html directory.

    (yes, this is for HStouch to use as a slide show)



    everything i've tried i've ended up with one error or another, i'm lost, and ready to increase my alcohol consumption

    thanks
Working...
X