|
i need to keep in a variable the thing that the user typed and then evaluate that string.i have dim str as string = textbox.text
and i want to use that variable str in order to evaluate that string.
My understanding is that you want to use the input from the user to call a function which would return a string.
If that is correct, my suggestion is to use Select Case.
dim str as string = textbox.text<br />
dim str2 as string<br />
<br />
Select Case str<br />
Case "function1"<br />
str2 = function1()<br />
Case "function2"<br />
str2 = function2()<br />
Case "function3"<br />
str2 = function3()<br />
.<br />
.<br />
.<br />
End Select
Am I close to understanding what you want?
|
|
|
|
|
yes this is what i want to do.
i thought that must be a way not to use something like select case since we don't know the input of the user.i suppose that there is no way in vb.net to do something like the one i described you that we can do in foxpro.
|
|
|
|
|
SQL does this, and I believe VBScript can do it, too. Hopefully, VB.NET doesn't, but it would not surprise me. Is there a command like EXEC, or EXECUTE, perhaps ?
Why would you want to do such a thing ? Basically, you want to take a string, and pass it to the compiler. VB.NET should be able to do this, seeing as .NET compiles on the fly anyhow.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Thanks for replying to my question.
Can you give me more information about the thing you suggested passing a string to the compiler vb.net in order to evaluate it.Any example or suggestion would be great.
Thanks in advance
|
|
|
|
|
I'm looking into serializing some of my classess to/from XML and need some help.
Imagine the scenario below (these are not my actual classes, but illustrate the problem)...
<br />
<br />
Public Class MyReport<br />
<br />
Public m_Title as String<br />
Public m_BackColor as Color<br />
Public m_Objects as new ArrayList ' Contains MyReportObject objects<br />
<br />
End Class<br />
<br />
Public Class MyReportObject<br />
<br />
Public m_Text as String<br />
Public m_X as Integer<br />
Public m_Y as Integer<br />
<br />
End Class<br />
How do I enable my two classes for serializing ?
I have tried adding different XML attributes to the class members and the Serializable attribute to the classes :
<br />
<br />
<Serializable()> Public Class MyReport<br />
<br />
<Xml.Serialization.XmlAttribute()> Public m_Title as String<br />
<Xml.Serialization.XmlAttribute()> Public m_BackColor as Color<br />
<Xml.Serialization.XmlElement()> Public m_Objects as new ArrayList ' Contains several MyReportObject objects<br />
<br />
End Class<br />
<br />
<Serializable()> Public Class MyReportObject<br />
<br />
<Xml.Serialization.XmlElement()> Public m_Text as String<br />
<Xml.Serialization.XmlElement()> Public m_X as Integer<br />
<Xml.Serialization.XmlElement()> Public m_Y as Integer<br />
<br />
End Class<br />
But I still get an error when I try to serialize the MyReport class ?
What am I doing wrong ?
|
|
|
|
|
Your class isn't attributed Serializable and/or does not implement the ISerializable interface. You can't just tag your classes properties with the attributes you have and expect it to work.
See the ISerializable Interface[^] docs for more information.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Sorry... actually, my classes are marked as serializable :
<br />
<Serializable()> Public Class MyReport<br />
<br />
<xml.Serialization.XmlAttribute()> Public m_Title as String<br />
<xml.Serialization.XmlAttribute()> Public m_BackColor as Color<br />
<xml.Serialization.XmlElement()> Public m_Objects as new ArrayList ' Contains several MyReportObject objects<br />
<br />
End Class<br />
<br />
<Serializable()> Public Class MyReportObject<br />
<br />
<xml.Serialization.XmlElement()> Public m_Text as String<br />
<xml.Serialization.XmlElement()> Public m_X as Integer<br />
<xml.Serialization.XmlElement()> Public m_Y as Integer<br />
<br />
End Class<br />
But somehow my code fails if the m_Objects arraylist contains objects MyReportObject - why ?
I have tried a number of different combinations so the code above isn't 100% accurate, but should give a good idea of what I'm trying to do.
Please help !!
|
|
|
|
|
Sorry for the above post... the forum somehow didn't recognize my account ?!?!?! (grrr!)
Anyway... the two classes ARE marked as < Serializable() > but not shown in the code above (again a forum bug ?)
Here the code AGAIN with the Serializable tags ...
<br />
<br />
< Serializable() > Public Class MyReport<br />
<br />
<xml.Serialization.XmlAttribute()> Public m_Title as String<br />
<xml.Serialization.XmlAttribute()> Public m_BackColor as Color<br />
<xml.Serialization.XmlElement()> Public m_Objects as new ArrayList ' Contains several MyReportObject objects<br />
<br />
End Class<br />
<br />
< Serializable() > Public Class MyReportObject<br />
<br />
<xml.Serialization.XmlElement()> Public m_Text as String<br />
<xml.Serialization.XmlElement()> Public m_X as Integer<br />
<xml.Serialization.XmlElement()> Public m_Y as Integer<br />
<br />
End Class<br />
<br />
|
|
|
|
|
Ok, so it is. It didn't come up before because the < and > brackets weren't typed in correctly. Not beacuse of a bug in CP's code.
Now, what about your serialization code?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Here's the current and complete test source including the test function :
<code>
Imports System.Xml.Serialization
<Serializable()> Public Class MyReport
Public m_Title As String
Public m_BackColor As Color
Public m_Objects As New ArrayList ' Contains several MyReportObject objects
End Class
<Serializable()> Public Class MyReportObject
Public m_Text As String
Public m_X As Integer
Public m_Y As Integer
End Class
Module TestFunctions
Public Sub Test()
' Making test data...
Dim oRep As New MyReport
oRep.m_Title = "Some new report..."
oRep.m_BackColor = oRep.m_BackColor.WhiteSmoke
Dim oObj As New MyReportObject
oObj.m_Text = "A text..."
oObj.m_X = 10
oObj.m_Y = 10
oRep.m_Objects.Add(oObj) ' Leave this line out, and serializeing below will succeed !
Try
' Serialize to XML file...
Dim file As New System.io.FileStream("c:\MyReport.xml", IO.FileMode.Create)
Dim ser As New System.Xml.Serialization.XmlSerializer(oRep.GetType)
ser.Serialize(file, oRep)
ser = Nothing
file.Close()
file = Nothing
MsgBox("Done!")
Catch ex As Exception
MsgBox(ex.Message & vbCr & vbCr & ex.InnerException.Message)
End Try
End Sub
End Module
</code>
|
|
|
|
|
OK. I didn't see this before, but since you have a complex object (MyReport) with a second level of serialization (ArrayList), the XML Formatter won't go into the ArrayList to serialize it. In other words, the XML Formatter is a Shallow formatter.
This article, Object Serialization in Visual Basic .NET[^], on MSDN will show you a handful of different scenarios for serializing different objects.
You can implement the ISerializable interface in your Report object and supply custom formatter code to get it to work with the XML Formatter. If you don;t want to do that, you'll have to switch to using one of the Deep formatters, either the Binary or SOAP formatters.
I would suggest implementing the ISerializable interface. It'll give your Serialization experience a very useful boost for future projects.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
What I need to do is record 2 types of audio at once. I have a program built that records audio via the mic but I need to add one more audio type to the mix but I'm not sure which it is? The program is going to be used to record IPPhone calls and things like that. So I want to us it with Skype, Yahoo and any other phone product. Right now I can only record half the conversation because the program picks up the mic but how do I get it to listen to the headphones to? Any help on this would be great, thank you!
|
|
|
|
|
use application.startuppath
|
|
|
|
|
Hi ,
I haven't work on vb6 but Try this
Application.StartupPath
I hope this will help u..........:->
Regards,
Ritesh
|
|
|
|
|
Hi Devs,
I want to create a window (form) that takes shape of an image inside it (or you can say any custom shape).
How can i do it.
Moreover, how can i create a moving animated character and give effects like when i click it some pop up will appear etc.
Thanks
Kumar
Kumar Saurabh
|
|
|
|
|
First set an image to the background of form then set Form's Transparent Color Property to Form's Background Color.
|
|
|
|
|
Thanks that did it.
Can you please suggest how can I get a animated gif work on a form.
Thanks
Kumar Saurabh
|
|
|
|
|
why havent u tried set a animated gif image to any picturebox control before asking this question,new bee?
|
|
|
|
|
I have been textbook programming out of a book called network programming in.net in the book instructs me to go to a couple of sites and download winpcap and rvpacket because we will need these two to build the next project well I did so I have completed the project everything looked good until I run the project I get the error "An unhandled exception of type 'System.NullReferenceException' occurred in WebInfo.exe Additional information: Object reference not set to an instance of anobject."
at the beginning of the project it did tell me to add a reference to Microsoft.visualbasic.compatibility I am at a complete loss could someone please help me the error is on the line below "packetquery = checkpacket query(adapter)"
-----------------------------------------------------------------------------
Option Strict Off
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub btnstart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
Dim Qid As Short
Dim PacketBuffer As String
Dim Adapters() As String
Dim openSuccess As Short
Dim PacketQueue As Short
Dim PacketLen As Short
Dim rawAdapterDetails As String
Dim posDefaultAdapter As Short
rawAdapterDetails = Space(MAX_ADAPTER_LEN)
getAdapterNames(rawAdapterDetails)
posDefaultAdapter = rawAdapterDetails.IndexOf(ADAPTER_DELIMITER)
Adapter = rawAdapterDetails.Substring(0, posDefaultAdapter)
openSuccess = openAdapter(Adapter)
If openSuccess <> ERR_SUCCESS Then
MsgBox("unable to start. check wincap is installer")
Exit Sub
End If
Do
PacketQueue = checkPacketQueue(Adapter)
For Qid = 1 To PacketQueue
PacketBuffer = Space(MAX_PACKET_SIZE)
PacketLen = getQueuedPacket(PacketBuffer)
PacketBuffer = PacketBuffer.Substring(0, PacketLen)
tbpackets.Text = tbpackets.Text & Replace(PacketBuffer, Chr(0), "")
tbpackets.SelectionStart = Len(tbpackets.Text)
System.Windows.Forms.Application.DoEvents()
Next
System.Windows.Forms.Application.DoEvents()
Loop
End Sub
Private Sub btnstop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstop.Click
closeAdapter(Adapter)
End Sub
Private Declare Function getAdapterNames Lib "rvpacket.dll" (ByVal s As String) As Short
Private Declare Function openAdapter Lib "rvpacket.dll" (ByVal Adapter As String) As Short
Private Declare Function checkPacketQueue Lib "rvpacket.dll" (ByVal Adapter As String) As Short
Private Declare Function getQueuedPacket Lib "rvpacket.dll" (ByVal s As String) As Short
Private Declare Sub closeAdapter Lib "rvpacket.dll" (ByVal Adapter As String)
Private Const SIMULTANEOUS_READS As Short = 10
Private Const MAX_ADAPTER_LEN As Short = 512
Private Const ADAPTER_DELIMITER As String = "|"
Private Const MAX_PACKET_SIZE As Short = 10000
Private Const ERR_SUCCESS As Short = 1
Private Const ERR_ADAPTER_ID As Short = 2
Private Const ERR_INVALID_HANDLE As Short = 3
Private Const ERR_INVALID_ADAPTER As Short = 4
Private Const ERR_ALLOCATE_PACKET As Short = 5
Public Adapter As String
End Class
|
|
|
|
|
Patience! We don't support 3rd party libraries here!
Try changing all your DECLARE statements that are returning Short's to Integer's. The return values coming from the functions in the C++ code are all returning DWORD's, or 32-bit unsigned integers. A Short in VB.NET is a 16-bit signed number, so your losing half of the data that makes up the return values from these functions:
Private Declare Function getAdapterNames Lib "rvpacket.dll" (ByVal s As String) As Integer
Private Declare Function openAdapter Lib "rvpacket.dll" (ByVal Adapter As String) As Integer
Private Declare Function checkPacketQueue Lib "rvpacket.dll" (ByVal Adapter As String) As Integer
Private Declare Function getQueuedPacket Lib "rvpacket.dll" (ByVal s As String) As Integer
Private Declare Sub closeAdapter Lib "rvpacket.dll" (ByVal Adapter As String)
Do the same for your constants:
Private Const SIMULTANEOUS_READS As Integer = 10
Private Const MAX_ADAPTER_LEN As Integer= 512
Private Const ADAPTER_DELIMITER As Integer= "|"
Private Const MAX_PACKET_SIZE As Integer= 10000
Private Const ERR_SUCCESS As Integer= 1
Private Const ERR_ADAPTER_ID As Integer= 2
Private Const ERR_INVALID_HANDLE As Integer= 3
Private Const ERR_INVALID_ADAPTER As Integer= 4
Private Const ERR_ALLOCATE_PACKET As Integer= 5
Then move these two sections to the top of the Class definition. The rest of the code LOOKS right, but I'm in no position to start putting together programs to test this library. Try checking to see what Adapter holds when you make that call to PacketQueue = checkPacketQueue(Adapter) . Make sure it's not blank.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Please Help me to find a particular record in a database using adodc
M.N.Patel
|
|
|
|
|
Hi all
how can I write programe in vb.Net to get thw URL from the address bar when any one use the internet explorer .
Please help me.
Thanks.
|
|
|
|
|
Hello,
I think the title says.
Your help is truly appreciated.
|
|
|
|
|
If you want to write a virus, I reckon C++ is the way to do it. VB.NET isn't even on the list.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Corrupt a folder? Don't ask, noone is telling.
Restrict access to it? Easy using NTFS permissions. Just right-click on the folder, click Properties, Security tab, and set permissions for the various/groups user as needed.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|