Results 1 to 6 of 6

Thread: C programmer stuck on VB6

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    Help, I`ve just starting a new job and my first task is to write a CanBus interface program in VB6. I`ve never used VB before (die hard C programmer). I am struggling with the passing / returning variables. I have got the hang of the ByVal when passing, but is there such a thing as return() aka C?
    My next problem is with the structure to the programming, in C things flow but as far as I can tell they happen all over the place in VB (event driven) If I have a form (say for setting up baud rate etc) whats the best way of storing the baud rate (after it has been altered by the user) so that I can access it from a different module? thanks in advance.

  2. #2
    Guest

    Post

    Dunno what the heck you're on about in the first paragraph (me not know much C but would like to)

    As for the second bit...

    Call the form with something like:
    Code:
    frmInput.Show vbModal
    but when the form is closed make it hide not unload, then use something like
    Code:
    lBaud=frmInput.txtBaud
    Unload frmInput
    in the calling procedure to get the variable.

    Make any sense?

    ------------------
    Matthew Ralston
    E-Mail: m.ralston@mediavault.co.uk
    ICQ:31422892
    Web Sites:The Blue Link My Home Page (Not up at the moment!)

  3. #3
    New Member
    Join Date
    Nov 1999
    Location
    l
    Posts
    13

    Post

    For the first part:

    I think you mean return values of functions.
    Well in vb it is:

    function TestFunction(varString as string) as string
    varstring = mid$(varstring,1,3)
    testfunction = varstring 'here the return value is filled

    end function

    For the second part you can use a database or the registry with savesetting or getsetting as standard vb functions or api calls to registry.

    ------------------

  4. #4
    New Member
    Join Date
    Jan 2000
    Posts
    3

    Post

    Hi Rick,

    As stated by Matthew, I do not know any C and does not know what you mean by a CanBus. As long as you can understand the difference in passing parameter values ByVAl and ByRef, you're halfway there.

    The easiest way (and to my simple logical way of programming) you create what they call Public variables that can be used through-out the entire application. So if you have a setup form that changes the baud rate, after "Accepting" the changed values or closing of the form , the Public varaibles will retain the value as long as the application is active (running).

    Add a new Module to the project and add the variables in the Declaration section of the Module...

    Public pintBaudRate as Integer

    ... and give the module an appropriate name.


    There are various ways to save the value, but make use of the Change, LostFocus, or better still the Query_UnLoad event of the Form to set the public variable pintBaudRate to the value of the object on the form e.g.

    pintBaudRate = txtBaudRate

    Hope this makes a little more sense




    ------------------

    Pierre

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Post

    Thanks for your help, I`ve got the hang of passing things around now (using Byref and ByVal) I`m still not sure of the best way of variable storage, public is a way of doing it but this is often frowned apon (at least in C programming circles) thanks again

  6. #6
    Member
    Join Date
    Nov 1999
    Location
    Dover, NH
    Posts
    54

    Post

    As far as storing the variable value - You could set a variable as a property to the form and only "get" access to it. A private variable within the would be used to set the public property value.

    Just a quick example - code may not be exact:

    Option Explicit
    Private lBaudrate As Long

    Private Sub cmdSetRate_Click()
    lBaudrate = Cint(txtBaudRate)
    End Sub

    Public Property Get TheBaudRate As Long
    TheBaudRate = lBaudrate
    and so on....

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