|
i'm trying to develop an addin for vb.net that allows the user to add a new (code created) class to the solution by right clicking on the solution in solution explorer and selecting a new context menu item from the list. this code will be dynamically generated based on some user input so cant be created by using a wizard.
i've been able to generate the class dynamically and add it to the solution etc. the one thing i havent been able to figure out is how to create the menu item so that it only appears when a "solution" type node is selected in the solution explorer window.
any help in this area would be appreciated
thanks in advance
swampy
|
|
|
|
|
I try to read data into array and display the data, however i only manage to get 1 in return. Below is my coding, may i have some suggestion and advice?
Option Strict On
Imports System.IO
Public Class Form1
Private Function Language(ByVal MLanguage As Integer, ByVal RequestDataID() As Integer, ByRef GetBackWord() As String) As String
Dim s As String = String.Empty
Dim Number As Integer = 0
Dim sFileName As String
If MLanguage = 1 Then
sFileName = "C:\testing.txt"
Try
Dim oFile As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim oReader As StreamReader = New StreamReader(oFile)
Dim a As Integer = 0
Do Until (Number = RequestDataID(a))
If Number < RequestDataID(a) Then
s = oReader.ReadLine()
Language = s
'GetBackWord(6) = s
Number += 1
a += 1
Else
s = oReader.ReadLine()
End If
Loop
oReader.Close()
oFile.Close()
Catch
GetBackWord(0) = "a."
End Try
ElseIf MLanguage = 2 Then
sFileName = "C:\Maklumat.txt"
Try
Dim oFile As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim oReader As StreamReader = New StreamReader(oFile)
Dim a As Integer = 0
Do Until (Number = RequestDataID(a))
If Number < RequestDataID(a) Then
s = oReader.ReadLine()
GetBackWord(a) = s
Number += 1
a += 1
Else
s = oReader.ReadLine()
End If
Loop
oReader.Close()
oFile.Close()
Catch
GetBackWord(0) = "a"
End Try
Else
sFileName = "C:\CMsg.txt"
Try
Dim oFile As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim oReader As StreamReader = New StreamReader(oFile)
'Dim a As Integer = 0
Do Until (Number = RequestDataID(6))
If Number < RequestDataID(6) Then
s = oReader.ReadLine()
GetBackWord(6) = s
Number += 1
'a += 1
Else
s = oReader.ReadLine()
End If
Loop
oReader.Close()
oFile.Close()
Catch
GetBackWord(0) = "a"
End Try
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Integer = 0
Dim sss() As String = {""}
Dim aaa() As Integer = {1, 2, 3, 4, 5, 6, 7}
'ReDim Preserve aaa(6)
Do Until a = 5
MessageBox.Show(Language(1, aaa, sss))
a += 1
Loop
End Sub
End Class
|
|
|
|
|
TeiUKei wrote: s = oReader.ReadLine()
Language = s
This seems redundant. Either way, your return value is being changed every time, not accumulated. Is that the intention ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
No, my intention is for example, everytime i receive a requestID(3), i will read 4 lines from the textfile and store in the array, GetBackWord(3) and display the lines i get. Any suggestion? I stuck there and be so appreciate for help.
|
|
|
|
|
I'm not really sure what you mean. The code looks messy - perhaps if you told us what's in the file, and what you expect the function to return ( and what you're getting instead ) ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, this is the data in the file
No,Title
1,Error Message
Information
Question
a
b
c
d
e
f
Let say i receive RequestDataID = {1,2,3,4,5,6,7}, then for RequestDataID(0),line 1 will be read and stored in GetBackWord(0) which then send back to the function called and same with the other. However, i only manage to get c in return. What should i suppose to do?
|
|
|
|
|
I honestly can't work out how this code is supposed to work. Really, what you should do is read the entire file into an array, File.ReadAllLines (from memory ) does this. Then you can copy whatever lines you want.
Other suggestion - set a breakpoint and step through your code to try and work out where it's going wrong.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, thanx for help anyway!!
|
|
|
|
|
I was hoping we might dig a little deeper. Does File.ReadAllLines ( or whatever it is ) help ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I checked my code and wondered if it was because RichTextbox only take the recent memory, that's why it only displayed one of it.
|
|
|
|
|
The rich text box will show exactly what you ask it to. If the function returns what you expect, then the problem is how you assign it to the rich text box.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, i solve the problem of display data. Thanx!!!
|
|
|
|
|
Is there an event or means of establishing when the user cancels a drag and drop operation?
Lets say the user is dragging something over my control. How will i know if the user cancelled the operation (i.e. by pressing escape)? Do i have to write custom code for it or is there an easy way?
Also, on a slightly related matter, how can i find out if the mouse button is down?
I need a mouse equivilent to My.Computer.Keyboard.CtrlKeyDown
Such as My.Computer.Mouse.LeftButtonDown
|
|
|
|
|
I think there's a syskey event for system keys. I know that the normal key events have flags for CTRL and ALT, so they don't generate an event by themselves ( I don't think )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i need a vb code for barcode Daily time record attendance. pls help. send it to my email add lustrac@yahoo.com or post it here.. thanks a lot..
chris
|
|
|
|
|
You seem to have this site confused with rentacoder.
There is code for reading barcodes on the site, the rest shouldn't be too hard. If it is, you can ask for help, but no-one will do your job for you.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
If you're writing any code, you can add parameters to the Paramaters collection. If you're not writing any code, I have no idea how all that wizard rubbish works.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I don't understand the question.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Probably a simple question but i have a class called LukeClass.
I have a Shared variable called LukeSharedVar in that class.
I do not create any instances of that class, but i call LukeClass.LukeSharedVar = "Luke"
Does a new instance get created? I dont understand what happens if you modify a shared property/variable of a class without having any instances of that class in memory...
|
|
|
|
|
No, setting the value of a static (shared in VB) member does not create an instance of the class.
The static members are stored in the memory area for the class. This memory area is allocated when the assembly is loaded. There is only set of the static members for a class, regardless if there are zero or a million instances of the class.
---
b { font-weight: normal; }
|
|
|
|
|
Excellent thanks for that.
|
|
|
|
|
Just to add to what's been said - a shared variable ( static in C# and C++ ) has the same value for all instances of the class, and if the variable is public, you can set it even if no instances exist ( although the existance of a public static variable is a bit of a red flag, what's it used for ? )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well in my case, i have a class which contains information about a booking. I create multiple instances of this class (for multiple bookings) and store them in an array and i then pass that array to another section of my code which goes through and processes each booking in the array.
Each booking (instance of my booking class) has a peice of information which is the same across all bookings i.e. it does not booking-specific information. So i create a shared variable which stores the non booking-specific information for my processing function to use.
Doing it this way seems nicer to me than settings the same value for each booking instance.
|
|
|
|
|
I'd have tended towards having a struct which contains a list of booking info and a single ID, or passing the ID and array to a method that stores them. What if you have more than one instance of the class ( it should probably be a struct, as well ) that relate to different bookings ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I could do that but it would be messier given the fact that everything i need is stored inside the array of bookinginfo class instances as opposed to having to pass extra parameters to other functions... It would require more coding and extra copies of the non booking-specific information lying around.
Im not sure i understand exactly what you're saying though... How would a structure be better?
|
|
|
|