Results 1 to 3 of 3

Thread: Syntax error

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    14

    Syntax error

    I have written the sub Below but when I call RegSetStr in a sub below
    I get a request from the compiler to use a "=" sign as if its a function
    Whats not making it a sub (VB6)

    Private Sub RegSetStr(ByRef FullLocation_Name As String, ByRef Str As String)
    Dim oReg As Object
    Set oReg = CreateObject("WScript.Shell")
    oReg.RegWrite FullLocation_Name, Str, "REG_SZ"

    Set oReg = Nothing
    End Sub

    Private Function GetWinReg(ByRef LocationName As String) As String
    Dim Str As String
    Dim Zeros As String
    Dim BaseLoc As String
    Zeros = "00000"
    BaseLoc = "SOFTWARE\Microsoft\Windows\TestProgram"

    RegCreateKey (BaseLoc)
    GetWinReg = RegGetStr(BaseLoc & LocationName)
    If Len(GetWinReg) < 1 Then
    RegSetStr(BaseLoc & LocationName, Zeros) ???????? error = BaseLoc
    GetWinReg = Zeros
    End If
    End Function

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Syntax error

    remove the parenthesis ... just pass the parameters... when you put the () around then. VB thinks you're calling a function...

    -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??? *

  3. #3
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    813

    Re: Syntax error

    Just to play Devil's Advocate (and because my VB code has to cohabit with lots of other, 'C'-style languages), I use the Call keyword, which forces the [consistent] use of braces:

    Code:
    If (Len(GetWinReg) < 1) Then
       
       Call RegSetStr(BaseLoc & LocationName, Zeros) 
       
       GetWinReg = Zeros
    End If
    Warning: Whichever "style" you choose, stick to it!

    Mixing and matching is a Bad Idea, especially when you start working with Object references:

    Code:
    SomeFunction (SomeObjectReference)
    Note the slightly odd placement of that space before the opening brace and then, at run-time, "marvel" at how your object reference "magically" transforms into its own Default Property when it "arrives" inside the function being called. )

    Regards, Phill W.

Tags for this Thread

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