|
Let me more specific. In my click evenhandler I raise a mouse even (right click), but for that the mouse should be located on the right place in the listboc, that is in a certain index, while I call upon it from another location in the code (things are executed programmatically).
|
|
|
|
|
Hi
can someone tell me what wrong with my code i get the nullreference exception I know its something obvious but still new to .net
here is the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
MsgBox(Spot(0).ToString)
End Sub
Function Spot() As Array
Dim ObjArray As Array
ObjArray = Nothing
Dim Obj1 As New Object
Dim Obj2 As New Object
Dim Obj3 As New Object
Obj1 = "Hello World"
Obj2 = 69
Obj3 = False
ObjArray(0) = Obj1 <-this is where the null reference is getting thrown
ObjArray(1) = Obj2
ObjArray(2) = Obj3
Return ObjArray
End Function
thanks everyone =)
|
|
|
|
|
Well, first of all, why do you want to create an array of all different types ? That kind of sucks.
Second, never use MsgBox, or any other things that exist only to make VB6 coders feel warm and fuzzy. Use the .NET stuff, such as MessageBox.Show. In this case, it doesn't matter much, but it's a good habit to get into.
Have you stepped through the code, to see what's happening ?
thedom2 wrote: ObjArray = Nothing
If your array object is 'nothing', then it's not an array, is it ? You would do better to use a dynamic container such as ArrayList. Either way, if you want to have an array with 3 objects in it, you need to call new to create it. You've done the opposite, you've told the compiler that there's no memory to assign yet, and no object exists.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
well ultimately i wanted a function that output 3 items(hence the array)
when i try the below line
dim objArray as NEW array
intellisense tells me "cannot be used on a class that is declared 'mustinherit'"
the objArray=nothing was me "trying" to debug/test the fucntion(that didnt work)
any suggestions oh wise one
|
|
|
|
|
worked it out this is the code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'this calls function and select 2nd array element
MessageBox.Show(Spot(1).ToString)
End Sub
Function Spot() As Array
Dim ObjArray As Array = Array.CreateInstance(GetType(Object), 3)
Dim Obj1, obj2, obj3 As Object
Obj1 = "Hello World"
obj2 = 69
obj3 = False
ObjArray(0) = Obj1
ObjArray(1) = obj2
ObjArray(2) = obj3
Return ObjArray
End Function
Christian you cant actually use new keyword on array member well thats what i read on msdn. you need to use createinstance to get the thing in memory and work with object. thanks for your help anyway
|
|
|
|
|
thedom2 wrote:
Christian you cant actually use new keyword on array member well thats what i read on msdn.
You typically wouldn't do this. In C# you'd do it like this
object [] ObjArray = new object[3];
I have no idea how it's done in VB, but I'm sure there's a way.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian Graus wrote: I have no idea how it's done in VB, but I'm sure there's a way
Indeed there is
Dim myArray() as Object = new Object(3){}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
i think it would be much more easier if you wrote a class that holds the data and put cllas-instances into an ArrayList:
' The class that holds the data
class mydata
public StringValue as string
public IntValue as integer
public BoolValue as Boolean
end class
' Your Function Spot
Function Spot() As ArrayList
Dim ObjArray As New ArrayList()
Dim clsInstance1 As New mydata
Dim clsInstance2 As New mydata
With clsInstance1
.StringValue = "Hello World"
.IntValue = 69
.BoolValue = False
End With
With clsInstance2
.StringValue = "Hello Again"
.IntValue = 96
.BoolValue = True
End With
ObjArray.Add(clsInstance1)
ObjArray.Add(clsInstance2)
Return ObjArray
End Function
' in your Button-Click:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim arrList as ArrayList = Spot()
MsgBox(arrList(1).IntValue.ToString())
End Sub
- walter
|
|
|
|
|
thanks Walter thats a great suggestions
cheers Dom
|
|
|
|
|
Hi
I am using getresponestream function to get a stream and read from it
but I need to seek.
what can I do?
Please help me.
thanks.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
You could try creating a FileStream based on the Stream returned.
However I don't think that will work because NetworkStreams are seekable.
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
I created an application and require the application to be launched from the “Windows Explorer” context menu. I created the context menu with the following code below “Sub AddToContextMenu”
I added the following code into “Sub Main” and “Sub New” (below). I set the start up object to sub main. The good news is that the application does launch from the context menu but it does not pass in the name of the file I want to open with my application.
Please Help.
Private Sub AddToContextMenu(ByVal V_Name As String, ByVal V_Path As String)
Dim regmenu As RegistryKey = Nothing
Dim regcmd As RegistryKey = Nothing
Try
regmenu = Registry.ClassesRoot.CreateSubKey(MenuName)
If Not regmenu Is Nothing Then
regmenu.SetValue("", V_Name)
regcmd = Registry.ClassesRoot.CreateSubKey(Command)
End If
If Not regcmd Is Nothing Then
regcmd.SetValue("", V_Path)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
#Region "Startup Application"
'The main entry point for the application.
<stathread()> Public Shared Sub Main(ByVal Args() As String)
Dim str_In As String = vbNullString
Try
str_In = Args(0).ToString
Catch ex As Exception
str_In = vbNullString
str_In = "C:\Temp\Error.xls"
End Try
Application.Run(New frm_Main(str_In))
End Sub
Public Sub New(ByVal vals As String)
MyBase.New()
'This call is required by the Windows Forms Designer.
InitializeComponent()
If Not vals = vbNullString Then
Dim frmFileAdd As New frm_FileAdd(vals)
Try
frmFileAdd.ShowDialog()
Catch ex As Exception
End Try
End If
End Sub
#End Region
Veghead
|
|
|
|
|
hai
iam working with vb.net2005 and sql2005
iam getting data from my database with support of dataset
but when i tried to enter new data through programe the data is updating the dataset but not the dataset
here iam my working logic here please follow and guide me what is worng in it
dim cn as new sqlconnection=("connection string")
cn.open()
dim da as new sqldataadaper("select * from table1",cn)
dim comda as new sqlcommandbuilder(da)
dim ds as newdataset
da.fill(ds,"table1")
dim drow as datarow
drow = ds.tables("table1").newrow
drow.item(0) = textbox1.text
ds.("table1").rows.add(drow)
da.update(ds,"table1")
Somebody please help me in this matter
ramu
|
|
|
|
|
If you are using the designers then a component called a TableAdaptor should have been added to the form. (Or you can reference it in code) you need to use this class to update the data to the database.
I have no idea what I just said. But my intentions were sincere.
|
|
|
|
|
hello, i am not very familiar with vb.net controls and i want to open a link from one WebBrowser control to another.For example when a link is being clicked in one window the infomration is loaded in a different WebBrowser.
Anybody that can help. thanks
Ol
|
|
|
|
|
You would have to find a way to pass the URL to the new browser window. You could do this by saving the URL somewhere (i.e. file), and then reading the file when the browser starts up to open the link.
I also think that there is a away to pass arguments to other programs, you could also try this.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
|
Hi Tom,
thanks for your reply. I had looked at the link for IE7_Clone and also tried the code you sent. It makes sence but it just doesnt work. I get highlighted errors. I am not sure where i go wrong but will keep trying. thanks for your help. Regards
Ol
|
|
|
|
|
I am having a hard time coding a program that I have been working on. Everytime I try to declare my variables,I get an error message. Help. Does anyone have examples?
Akil
|
|
|
|
|
Maybe posting a snipped of the code, together with the error message, will help us (and you).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
What resources do you have ? If you're unable to declare a variable, my advice would be that you need to buy a simple book and work through it.
Posting such a question without any example code or error info also makes it impossible for anyone to help you.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Assuming you mean simple things like declaring a variable and assigning a value to it I think this simple sample should do the trick:
Dim a as String 'Declares a string variable with the name a, but doesnt assign a value<br />
Dim b as New Form() 'Declares a form variable with the name b and assigns a new instance of a form to it<br />
<br />
a = "Hello World"
Cheers.
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
Hi all,
what is the main differences b/w VB & VB.NET? also please can any one tell me the difference b/w
VB.NET & C#?
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Rahithi wrote: what is the main differences b/w VB & VB.NET?
That would take forever to explain. See here:
Wikipedia VB.NET
Wikipedia C#
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Rahithi wrote: VB & VB.NET?
VB6 was not a real language. VB.NET is, sort of.
Rahithi wrote: VB.NET & C#?
VB.NET is loosely typed, and carries a lot of legacy VB garbage ( easily removed, never use the VisualBasic namespace ). C# is strongly typed, is a new language with no legacy stuff, and is subject to an independent standard. IMO, VB.NET exists to make the VB6 crowd happy, C# is meant to be a new and compelling language.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|