Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: ______ on May 18, 2004, 05:59 PM

Title: help on Usercontrols
Post by: ______ on May 18, 2004, 05:59 PM
How do i get class/modules to interact with Usercontrol winsocks. Every time I tried the winsock is not found.
Title: Re:help on Usercontrols
Post by: CrAz3D on May 19, 2004, 11:43 AM
Maybe something like this?:

This is in the UserControl:

Public Sub Winsock(Action as string, Address as string, Port as string)
if Action = "Connect" then
 Winsock1.Connect address, port
end if
end sub


Code in the Class/Modules:

UserControl1.Winsock Connect, "bnls.valhallalegends.com", "9367"


Didn't know if this would work, but it does.  There is *most likely* an easier way, but this is all I could think of off the top of my head.
Title: Re:help on Usercontrols
Post by: ______ on May 19, 2004, 12:37 PM
I tried that out and it didnt work, first try was just a winsock on a blank usercontrol with a winsock named winsock1 with the code, compiled and it said object not found.
Title: Re:help on Usercontrols
Post by: CrAz3D on May 19, 2004, 02:28 PM

This is in the UserControl:

Public Sub THEWINSOCK(Action as string, Address as string, Port as string)
if Action = "Connect" then
 Winsock1.Connect address, port
end if
end sub


Code in the Class/Modules:

UserControl1.THEWINSOCK Connect, "bnls.valhallalegends.com", "9367"



Now that I renamed a few things try it, it might make more sense to you.  It works, I tried it.
Title: Re:help on Usercontrols
Post by: Flame on May 19, 2004, 04:13 PM
I'm not sure if this would give the same error as what you are saying, but make sure for the usercontrol that Public = True, I ran into that problem a few times.
Title: Re:help on Usercontrols
Post by: ______ on May 19, 2004, 04:44 PM
I did exactly what you said

Module

Public Function Connection()
UserControl1.THEWINSOCK Connect, "bnls.valhallalegends.com", "9367"
End Function


Usercontrol

Public Sub THEWINSOCK(Action As String, Address As String, Port As String)
If Action = "Connect" Then
 Winsock1.Connect Address, Port
End If
End Sub

Private Sub UserControl_Click()
Connection
End Sub


When i type in usercontrol1  then "." no public functions or subs appear in the module and i have control set to public.

When i compile and add to a new exe, i run it and click the drawn ocx area i get Object not found. No clue what im doing wrong.
Title: Re:help on Usercontrols
Post by: Grok on May 19, 2004, 05:01 PM
Quote from: ___/\___ on May 19, 2004, 04:44 PMI did exactly what you said

Module
Public Function Connection()
   UserControl1.THEWINSOCK Connect, "bnls.valhallalegends.com", "9367"
End Function


Usercontrol
Public Sub THEWINSOCK(Action As String, Address As String, Port As String)
   If Action = "Connect" Then
       Winsock1.Connect Address, Port
   End If
End Sub

Private Sub UserControl_Click()
   Connection
End Sub

When i type in usercontrol1  then "." no public functions or subs appear in the module and i have control set to public.

When i compile and add to a new exe, i run it and click the drawn ocx area i get Object not found. No clue what im doing wrong.

First off, your Action is a string, yet you are not passing a string.  Connect should be in string quotes.
Second, you may not know what you're doing wrong, but you don't know what you're doing right, either.  What is it precisely that you want to do?
Title: Re:help on Usercontrols
Post by: ______ on May 19, 2004, 05:08 PM
Im trying to have class access a winsock on the usercontrol to send data.
Title: Re:help on Usercontrols
Post by: Grok on May 19, 2004, 06:36 PM
Quote from: ___/\___ on May 19, 2004, 05:08 PM
Im trying to have class access a winsock on the usercontrol to send data.

Is the class owned by the UserControl, or is the class owned by the application which contains the form on which you drop the UserControl?
Title: Re:help on Usercontrols
Post by: ______ on May 19, 2004, 06:37 PM
it is owned by the Usercontrol.
Title: Re:help on Usercontrols
Post by: AntiFlame on May 20, 2004, 06:07 PM
You will need to provide accessor functions in order to access the Winsock within the UserControl.  This is because the Winsock control is initialized as a private object module within the UserControl.  So you will need to add functions like:

(Inside of the UserControl's code)

Private Sub Connect(Optional ByVal Server As String = "Default Server", Optional ByVal Port As Long = DefaultPort)
   Winsock1.Connect Server, Port
End Sub


You will need to provide similar functions for all of the Winsock's functionality that you want to duplicate.
Title: Re:help on Usercontrols
Post by: ______ on May 20, 2004, 06:59 PM
What i was trying to say before is none of my class's or modules coud not access anything public on the usercontrol.
Title: Re:help on Usercontrols
Post by: AntiFlame on May 20, 2004, 11:05 PM
As I just explained, any controls you create within the UserControl container are private object modules.
Title: Re:help on Usercontrols
Post by: CrAz3D on May 21, 2004, 10:24 AM
Are you using the correct name when tryibng to acess the usercontrol?...

I accidently did UserControl1...but there should've been two 1s..(UserControl11)