Avatar billede dingemann Novice
24. juli 2008 - 18:54 Der er 5 kommentarer og
1 løsning

mulig variabel-fejl

okay... jeg er selv begyndt at løse mit spørgsmål på http://www.eksperten.dk/spm/839245 og har til formålet fundet en kodestump. Jeg har modficeret så den passer i retningen af hvor jeg vil hen men jeg får en fejl som jeg ikke helt ved hvordan jeg skal debugge:

' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName, ByVal filePath)
  If filePath = 0 Then
      Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
  Else
      Dim ScriptDir: ScriptDir = filePath
  End If

  wscript.echo ScriptDir
  Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
  IncludeFileAbs FileName
End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
  Const ForReading = 1
  Dim f: set f = fso.OpenTextFile(FileName,ForReading)
  Dim s: s = f.ReadAll()
  ExecuteGlobal s
  End Sub

' Includes the configuration file.
' The configiguration file has the name of the main script
' with the extension ".config".
Private Sub ReadConfigFile
  Dim ConfigFileName: ConfigFileName = fso.GetBaseName(WScript.ScriptName) &
".config"
  IncludeFile ConfigFileName, "\\emw2003dc\scripts$\"
  End Sub

ReadConfigFile

WScript.Echo "ConfigParm1=" & ConfigParm1
WScript.Echo "ConfigParm2=" & ConfigParm2
Sub1


---------

jeg har selv tilføjet If strukturen

  If filePath = 0 Then
      Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
  Else
      Dim ScriptDir: ScriptDir = filePath
  End If


og fejlen opstår i Else-delen med Dim ScriptDir: ScriptDir = filePath muligvis fordi filePath er forkert type.
Jeg er ret ny i vbs og har ikke helt styr på hvordan jeg fixer fejlen.


(Den oprindelige sovs til ovenstående vbs kan findes her http://www.source-code.biz/snippets/vbscript/5.htm hvis nogen vil se den ikke-modificerede version)
Avatar billede morten_leth Nybegynder
31. juli 2008 - 13:52 #1
Hmm, jeg ser et par problemer med det du har lavet der.. ;)

Dim fso
Dim scriptdir


set fso = CreateObject("Scripting.FileSystemObject")

  If filePath = 0 Then
      ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
  Else
      ScriptDir = filePath
  End If
msgbox scriptdir

Jeg lavede lige denne her...

Din måde at declare (det du gør når du skriver dim) er lidt forkert... måden man normalt declare en variabel i vbscript er ved blot at skrive

dim variabelnavn

Plus at declare den 2 gange er os lidt forkert....

Ergo hvis jeg skulle have lavet det havde jeg valgt at gøre således.

' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso, ScriptDir, FileName
set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName, ByVal filePath)
  If filePath = 0 Then
      ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
  Else
      ScriptDir = filePath
  End If

  wscript.echo ScriptDir
  FileName = fso.BuildPath(ScriptDir,RelativeFileName)
  IncludeFileAbs FileName
End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
  Const ForReading = 1
  Dim f
  set f = fso.OpenTextFile(FileName,ForReading)
  Dim s
  s = f.ReadAll()
  ExecuteGlobal s
  End Sub

' Includes the configuration file.
' The configiguration file has the name of the main script
' with the extension ".config".
Private Sub ReadConfigFile
  Dim ConfigFileName
  ConfigFileName = fso.GetBaseName(WScript.ScriptName) &
".config"
  IncludeFile ConfigFileName, "\\emw2003dc\scripts$\"
  End Sub

ReadConfigFile

WScript.Echo "ConfigParm1=" & ConfigParm1
WScript.Echo "ConfigParm2=" & ConfigParm2
Sub1


Den sidste sub1 forstår jeg så ikke lige, den vil du os få en fejl på da du starter en sub uden af afslutte den...
Avatar billede dingemann Novice
12. august 2008 - 22:54 #2
undskyld det sene svar. Jeg har været på ferie i Prag :)
Jeg tester lige - og så skal du nok få besked. Sub'en som du ikke forstår er der heller ikke meget at forstå med... den er bare til for at vise at den kan køres :)
Avatar billede dingemann Novice
20. oktober 2008 - 14:13 #3
hey Morten...
Jeg fandt løsningen (for tre uger siden) og din hjælp var ganske fin. Løsningen blev som følger:

' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Importscript

Dim fso, i, ScriptDir, colDrives, WshNetwork, FileName, objConnection, objCommand, FindUser, strUser, objRecordSet, strDN, intLength, intNameLength, arrPath, OUName
set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName, ByVal filePath)
    If filePath = "" Then
      ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
    Else
      ScriptDir = filePath
    End If
    FileName = fso.BuildPath(ScriptDir,RelativeFileName)
    IncludeFileAbs FileName
End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
    Const ForReading = 1
    Dim f
    set f = fso.OpenTextFile(FileName, ForReading)
    Dim s
    s = f.ReadAll()
    ExecuteGlobal s

End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' reading the configfiles
' Includes the configuration file.
' The configiguration file has the name of the main script
' with the extension ".config".
Private Sub ReadConfigFile
    Dim ConfigFileName
    ConfigFileName = fso.GetBaseName(WScript.ScriptName) & ".config"
    IncludeFile ConfigFileName, "\\emw2003dc\scripts$\"
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' getting the current username

Public Function getCurrentUserName ()
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    getCurrentUserName = WshNetwork.UserName
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Netværkdrevs-mounting
Public Sub mountingDevices()

    Const ADS_SCOPE_SUBTREE = 2

    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =  CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection

    'FindUser = InputBox("Please Enter A UserName", "Find User OU")
    FindUser =  getCurrentUserName
    If FindUser = "" Then
        MsgBox("No UserName Was Added")
        WScript.Quit
    Else
        strUser = FindUser
    End If
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT distinguishedName FROM 'LDAP://dc=DOMÆNE,dc=dk' WHERE objectCategory='user'AND sAMAccountName='" & strUser & "'"
      Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
        strDN = objRecordSet.Fields("distinguishedName").Value
        arrPath = Split(strDN, ",")
        intLength = Len(arrPath(1))
        intNameLength = intLength - 3
        OUName = Right(arrPath(1), intNameLength)
        'Wscript.Echo "User :" & strUser & "_OU_" &OUName
        objRecordSet.MoveNext
    Loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' removing existing mapped devices
    On Error Resume Next
    Set colDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to colDrives.Count-1 Step 2
        WshNetwork.RemoveNetworkDrive colDrives.Item(i)
    Next

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Default mounting new devices

    If OUName <> "" Then   
        WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Extra mounting for different OU Groups
    If OUName = OULevel2 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
   
    If OUName = OULevel3 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
    If OUName = OULevel4 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
    If OUName = OULevel5 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
    If OUName = OULevel6 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive publicFolderLetter, (publicFolders), True
    End If
    If OUName = OULevel7 Then
        'WshNetwork.MapNetworkDrive privateFolderLetter, (privateFolder & getCurrentUserName), True
        'WshNetwork.MapNetworkDrive PublicFolderLetter, (publicFolders), True
    End If
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Start!

ReadConfigFile
mountingDevices
WScript.Quit


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' END

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' .config-filen med samme fornavn som scriptfilen og placeret samme sted som scriptfilen





' This is a sample configuration file.

' Defining Libraries
Const privateFolder = "\\emw2003dc\usersmydocuments$\"
Const publicFolders = "\\emw2003dc\publicFolders$"
Const privateFolderLetter = "X:"
Const publicFolderLetter = "Y:"

' Defining OU-levels
Const OULevel1 = "Entire Up-Site"
Const OULevel2 = "Administration"
Const OULevel3 = "Backend"
Const OULevel4 = "Developer"
Const OULevel5 = "Freelancer"
Const OULevel6 = "Graphic"
Const OULevel7 = "Support"


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' END SCRIPT


Hvis du vil ha point så smid et svar!
Avatar billede dingemann Novice
15. december 2008 - 23:19 #4
jeg tager det som et nej
Avatar billede dingemann Novice
15. december 2008 - 23:19 #5
... i såfald så sig lige til :)
Avatar billede morten_leth Nybegynder
16. december 2008 - 09:21 #6
*sagt til mig selv*
Godmorgen mand har du sovet godt... :D

Det er helt i orden jeg har ikke brug for pointene så det er fint med mig..
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester