|
You should always use the fully qualified path to a file and not just assume the current directory is the one you think it is.
If your file is in the same folder as your .EXE, you can get the full path using something like:
Public Shared Function GetFullPathToFile(ByVal filename As String) As String
Return Path.Combine(Application.StartupPath, filename)
End Function
If it's in a subfolder of your application's folder, there are several different ways of building the path. A simple implementation would be something like:
Public Shared Function GetFullPathToFileInDataFolder(ByVal filename As String) As String
' Build the full path to the Data folder in our the folder our .EXE is in.
' You could also get this path from a config file, or some other data store.
Dim dataFolderPath As String = Path.Combine(Application.StartupPath, "Data")
' Then build the path to the requested file
Return Path.Combine(dataFolderPath, filename)
End Function
|
|
|
|
|
hi all
i have some lines of code which generarte menu at run time.now i want to pass the index value of menu to another function.hw to do so plz help me....
[code]
For i = 1 To n
s = "Select account from cash"
com = New OleDbCommand(s, con)
con.Open()
dr = com.ExecuteReader
While dr.Read()
a = dr(0)
b = a
Dim mSubSubMenuItem As System.Windows.Forms.MenuItem
mSubSubMenuItem = New System.Windows.Forms.MenuItem
mSubSubMenuItem.Index = i
mSubSubMenuItem.Text = b
mSubSubMenuItem.Enabled = True
mSubSubMenuItem.Visible = True
AddHandler mSubSubMenuItem.Click, AddressOf MenuClickHandler
mShowMenuItem.MenuItems.Add(mSubSubMenuItem)
i = i + 1
End While
[/code]
i want to pass the value of i to MenuClickHandler
poonam
|
|
|
|
|
easyst way would be to put i into the tag property of mssubsubmenuitem
then in you'r menuclickhandler cast sender to a menuitem and you can extract i from the tag property again
code would look something like this:
While dr.Read()
a = dr(0)
b = a
Dim mSubSubMenuItem As System.Windows.Forms.MenuItem
mSubSubMenuItem = New System.Windows.Forms.MenuItem
mSubSubMenuItem.Index = i
mSubSubMenuItem.tag = i
mSubSubMenuItem.Text = b
mSubSubMenuItem.Enabled = True
mSubSubMenuItem.Visible = True
AddHandler mSubSubMenuItem.Click, AddressOf MenuClickHandler
mShowMenuItem.MenuItems.Add(mSubSubMenuItem)
i = i + 1
End While
private sub MenuClickHandler (sender as object , e as system.eventargs)
Dim menu As System.Windows.Forms.MenuItem = sender
dim i as integer = menu.tag
end sub
hope it helps
If my help was helpfull let me know, if not let me know why.
The only way we learn is by making mistakes.
|
|
|
|
|
I add items to a listbox using a button and remove using another. How can I disable the remove button if there are no contents in the listbox
|
|
|
|
|
if listbox.items.count = 0 then
me.removebutton.enabled = false
end if
|
|
|
|
|
dexter9703 wrote: I add items to a listbox using a button and remove using another. How can I disable the remove button if there are no contents in the listbox
Me.RemoveButton.Enabled = (Me.ListBox.Items.Count>0)
|
|
|
|
|
I intended to have the App.config file as a sort of config.ini file and have set up many application variables there.
However i noticed that the .exe file does'nt complain if the app.config file is not around, so i can only assume that the file is embeddded into the exe file when the solution is built.
Is this so or can i update the app.config file for different situations without having to change code?
Regards
|
|
|
|
|
An app.config file is not required to run the app. It just sets certain options in your app when it runs, or is used to store values for future use. The file is NOT required to run the code.
Also, it's not compiled into the .EXE. It always stands as it's own seperate file.
|
|
|
|
|
Hi all...
I have the following piece of code:
Using HeaderReader As New StreamReader(HeaderFilePath)<br />
While Not HeaderReader.EndOfStream<br />
Dim EndFileHeaderWriter As New StreamWriter(filepath, True)<br />
EndFileHeaderWriter.WriteLine(HeaderReader.ReadLine())<br />
EndFileHeaderWriter.Close()<br />
End While<br />
End Using
Now i wanted to write a flat file and each line should be in a new line... instead this code is adding the text next to the previouse line... Like so...
Test line1Test line2Test line3
i wanted it like this...
Test line1
Test line2
Test line3
What am i doing wrong?
i am using the WriteLine and not the Write ???
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
If WriteLine isn't doing it, try adding Environment.NewLine to create a line break. That's what WriteLine does, tho. If you step through, are you sure that each line you are looking for is read seperately ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
oh... i think i understand what you mean... it could be that it is reading all the lines at the same time so in memory it is:
"Test line1Test line2Test line3" and that is why it is writing the whole line "Test line1Test line2Test line3" and then inserting the break.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Okay
It appears that you were right...
Thank you.
The source file used to read the text lines from is where the problem is... the text is Test line1Test line2Test line3 (so i have to fix the source file) thank you.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Sorry to be bothering you again...
You would know by any chance how to add a break point when using a "Flat File Destination" in SSIS. I want to add a break point after each row from the table... as it stands now... the table rows get written next to each other in the flat file.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
I have a datagridview control in which i have got a column of type DataGridViewComboBoxColumn. I populate this column's combo when I load the form. But while running if i click on the column's drop down button, so that I can view the list of data in the combobox of the column, it takes 2-3 seconds to show me the list. How can I speed up this drop down of the list so that I can make the application faster.
Thanks in Advance.
Sekhar
|
|
|
|
|
You got your answer here[^]. It's a shame you chose to ignore what Christian posted and just restate your question.
Again, how many items are in this combo?? Where is the data comming from?
|
|
|
|
|
Hi! I couldnt maintain the state of the treeview after postback. searched all over but i could seem to solve the problem. below is the code that i am using so it will be easier to understand whta i am doing.
Imports System.Data.SqlClient
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI.WebControls
Partial Public Class tree
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
TreeView1.CollapseAll()
' get the saved state of all nodes.
Dim treeViewState As New TreeViewState()
treeViewState.SaveTreeView(TreeView1, Me.GetType.ToString())
End Sub
Private Sub PopulateRootLevel()
Dim objConn As New SqlConnection("server=APEX-KEV3;uid=sa;pwd=password2133;database=TaxnologyOnlineDev")
Dim objCommand As New SqlCommand("select LocationId,LocationName,(select count(*) FROM Location " _
& "WHERE parentlocationid=sc.locationid) childnodecount FROM Location sc where parentlocationID is null and locationid=3", _
objConn)
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, TreeView1.Nodes)
End Sub
Private Sub PopulateNodes(ByVal dt As DataTable, ByVal nodes As TreeNodeCollection)
For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()
tn.Text = dr("locationname").ToString()
tn.Value = dr("locationid").ToString()
nodes.Add(tn)
'If node has child nodes, then enable on-demand populating
tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
Dim objConn As New SqlConnection("server=APEX-KEV3;uid=sa;pwd=password2133;database=TaxnologyOnlineDev")
Dim objCommand As New SqlCommand("select LocationId,LocationName,(select count(*) FROM Location " _
& "WHERE parentlocationid=sc.locationid) childnodecount FROM Location sc where parentlocationID=@parentID", _
objConn)
objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid
Dim da As New SqlDataAdapter(objCommand)
Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End Sub
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
PopulateSubLevel(CInt(e.Node.Value), e.Node)
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TreeView1.SelectedNodeChanged
If TreeView1.SelectedNode.Value <> String.Empty Then
Response.Redirect("tree.aspx?id=" + TreeView1.SelectedNode.Value)
End If
End Sub
Protected Sub TreeView1_Unload(ByVal sender As Object, ByVal e As EventArgs) Handles TreeView1.Unload
' save the state of all nodes.
Dim tvs As New TreeViewState
tvs.SaveTreeView(TreeView1, Me.GetType().ToString())
End Sub
End Class
Public Class TreeViewState
Public Sub SaveTreeView(ByVal treeView As TreeView, ByVal key As String)
Dim list As New List(Of System.Nullable(Of Boolean))()
SaveTreeViewExpandedState(treeView.Nodes, list)
HttpContext.Current.Session(key + treeView.ID) = list
End Sub
Private RestoreTreeViewIndex As Integer
Public Sub RestoreTreeView(ByVal treeView As TreeView, ByVal key As String)
Dim list As New List(Of Nullable(Of Boolean))
If HttpContext.Current.Session(key + treeView.ID) IsNot Nothing Then
list = CType(HttpContext.Current.Session(key + treeView.ID), List(Of Nullable(Of Boolean)))
End If
RestoreTreeViewIndex = 0
RestoreTreeViewExpandedState(treeView.Nodes, list)
End Sub
Private Sub SaveTreeViewExpandedState(ByVal nodes As TreeNodeCollection, ByVal list As List(Of System.Nullable(Of Boolean)))
For Each node As TreeNode In nodes
list.Add(node.Expanded)
If node.ChildNodes.Count > 0 Then
SaveTreeViewExpandedState(node.ChildNodes, list)
End If
Next
End Sub
Private Sub RestoreTreeViewExpandedState(ByVal nodes As TreeNodeCollection, ByVal list As List(Of System.Nullable(Of Boolean)))
For Each node As TreeNode In nodes
If RestoreTreeViewIndex >= list.Count Then
Exit For
End If
node.Expanded = list(System.Math.Max(System.Threading.Interlocked.Increment(RestoreTreeViewIndex), RestoreTreeViewIndex - 1))
If node.ChildNodes.Count > 0 Then
RestoreTreeViewExpandedState(node.ChildNodes, list)
End If
Next
End Sub
End Class
i am using visual studio .net 2.0 treeview control
please help
thanks
|
|
|
|
|
This question really belongs in the ASP.NET forum. It really has nothing to do with VB.NET.
But, I'm no expert in ASP.NET, but take a look in this code in your Page Load event:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
TreeView1.CollapseAll()
' get the saved state of all nodes.
Dim treeViewState As New TreeViewState()
treeViewState.SaveTreeView(TreeView1, Me.GetType.ToString())
End Sub
It would appear that you're collapsing all the treenodes in the tree on every postback, then saving the closed up state, which you don't even need to do since you're letting the state you saved drop out of scope.
|
|
|
|
|
Well, as you all might know by now, I'm new to vb.net. My question is, how would you delete a line of text from a text file without leaving the space? and is this possible without using 'buffers' or temp files , just the built in functions ... i hope this makes sense ...
gHoSt
|
|
|
|
|
The only way to modify a file is to read it all, modify it in memory and write it out again.
I do believe the File class has static methods which wrap all of this, but internally, that's the only way it can be done.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
well you are already putting these lines in to an array correct? Try to remove the line from the array then write all the elements from the array as the new content.
|
|
|
|
|
I have a vb6 activex control to print PDF and an HTML page one after the other.
ActiveX control uses webbrowser control to print html page.
I use the following Code to print html in vb form containing web browser control:
Private Sub wbrPrintHTML_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
wbrPrintHTML.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub
This control is accessed from asp.net application using javascript.
Application needs to print multiple PDF documents and html pages in the sequence pdf1,html1,pdf2,html2...
When this code is executed , in win XP ,it follows the right sequence (pdf1,html1,pdf2,html2...)
in the print queue.
In win 2000 sp4 and sp3 machines, the print queue changes to PDF1,PDF2,Html1...
Please suggest as how to resolve this.Is there any way to get information when the html printing is completed?
How to get the proper print queue sequence in win 2000 sp4 and sp3 machines?
Ravi
|
|
|
|
|
This question belongs in the web development forum. This would have to be done entirely client-side in JavaScript, though I have no idea how to do it.
Also, code running inside a browser session has no permissions to get any information about the machine it's running on. I'm guessing that the print queue configuration would be off-limits to your JavaScript code.
|
|
|
|
|
Hello,
Im basically just trying to find a way to fade in and out a button in VB.net - i just can't find anything on the internet to tell me how i could do this so I haven't even attempted myself.
I was wondering if anyone knew anything to start me going? or any URLs?
Any help would be amazing! thanks!
|
|
|
|
|
Just use a timer and set the opacity of the control.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
The controls don't have an Opacity property. Only the Form class does.
He'd have to put the controls in a Form container, set it's BorderStyle to None, create an instance of it at runtime, set it's TopLevel property to False, and then treat it like a Panel control. Follow??
|
|
|
|