|
In a VB.NET 2008 desktop application, I need to add some initial selections with a corresponding button to the 'main' form, before any of the normal
processing is allowed to occur. Thus due to that fact, I have the following questions to ask:
1. This application is using a System.Windows.Forms.MainMenu and I would like the 'File' option to not display until the 'new' button is clicked? If this is
possible, would you showe me the code for this to occur?
2. If option #1 is not possible, is there a way to make System.Windows.Forms.MainMenu not display until the the 'new' button is clicked? If this is possible,
would you show me the code for this to occur?
3. In this application there is code that adds menu items with logic like,
MainMenu1.MenuItems(0).MenuItems.Add("New Item", New EventHandler(AddressOf ClickHandler))
MainMenu1.MenuItems(0).MenuItems.Add("-")
Is there a way to modify the order of list of menuitems after the menu items have already been created? Would I need to delete the menuitems at that point and create the menuitems again? Thus would you show me the code for this option and/or let me know if this option is not possible?
|
|
|
|
|
1. Set the menu item's visibility property to False so it will not show on the form. You then set it to True when required.
2. NA
3. You would need to delete them and re-insert them.
|
|
|
|
|
In response to your answers, I have the following questions:
"Set the menu item's visibility property to False so it will not show on the form. You then set it to True when required." I placed the following code in the application, and it did not work:
MainMenu1.MdiListItem.Visible = False
Thus can you show me the code to Set the menu item's visibility property to False?
Also would you show me the code on how to 'You would need to delete them and re-insert them' the menuitems? The menu items are currently created in the gui and not in code.
|
|
|
|
|
classy_dog wrote: can you show me the code to Set the menu item's visibility property to False? The code you have should do it, I just tested it on my sample and it works fine.
The menu items are created in code within the form designer, whose code can be viewed, so you can see how it is created. You can also read the MSDN documentation[^] for full details.
|
|
|
|
|
Can u please tell me how to get internet time using a http request. i have a class named clsHttpRequests. But i know not know how to do that using vb6.
|
|
|
|
|
|
|
Hi All,
Hope I've got the correct forum.
I am writing code to copy data from one server to another. The database name and table is the same on both servers. The code I have written is as follows:
Function MoveDataToOtherServer() As Boolean
Dim conSource, conTarget As New SqlClient.SqlConnection
Dim cmdSource, cmdTarget As New SqlClient.SqlCommand
Dim strServerSource, strServerTarget As String
Dim strDatabase, strUsername, strPassword As String
Dim strColNames As String
Dim intCount As Integer
MoveBetsToOtherServer = False
strServerSource = "SERVERSource"
strDatabase = "testDBase"
strUsername = "sa"
strPassword = "password"
strServerTarget = "SERVERTarget"
Try
conSource.ConnectionString = "Data Source="& strServerSource & "; Initial Catalog=" &"strDatabase"& "; Integrated Security=False; User ID=& "strUsername & "; Password=" &"; strPassword &"; Connect Timeout=30"
conSource.Open()
cmdSource.Connection = conSource
conTarget.ConnectionString = "Data Source="& strServerTarget & "; Initial Catalog=" &"strDatabase"& "; Integrated Security=False; User ID=& "strUsername & "; Password=" &"; strPassword &"; Connect Timeout=30"
conTarget.Open()
cmdTarget.Connection = conTarget
cmdTarget.CommandText = "INSERT INTO SERVERTarget.dbo.testDBase.testTbl (" & " strColNames & ") SELECT " & "; strColNames & " FROM SERVERSource.dbo.testDBase.testTbl;"
intCount = cmdTarget.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conSource.Close()
conTarget.Close()
End Try
End Function
The ExecuteNonQuery() generates this message:
Could not find the server name 'SERVERSource' in sys.server. Werify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
Now I could make them linked servers but am not sure what effects this has later or on other code. I suppose I have 2 questions:
1: Is there a down side to linking the servers
2: If there is, is there another way I can copy across the data?
|
|
|
|
|
Is the server that you want to copy data from really named "SERVERSource"?
I doubt it is. If you can create a linked server (requires the same information as a connectionstring), then you can simply execute the command using any command line against the server - no need for code.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I attempted a small VBA Sub() in Excel 2013 with the intent of:
- iterating through a list of high volume ETFs on the Main worksheet,
- creating a Web Query for each ETF to access Security Holdings info for each ETF,
- pull that data into an individual worksheet for each ETF.
My issue is getting past the Fidelity secure access. The code below processes my password input correctly, but not my username. Being logged into the Fidelity website in an open browser session does not allow the web query access to the ETF data pages.
Can anyone tell me why the username portion of the code is failing? Is there an easier way for me to skin this cat?
Thanks
=====
Sub Update()
' Requires a reference to MICROSOFT INTERNET CONTROLS object
On Error GoTo ErrorOut:
Dim wbThis As Workbook: Set wbThis = ThisWorkbook
Dim wsMain As Worksheet: Set wsMain = wbThis.Worksheets("Main")
Dim objIntExp As InternetExplorer: Set objIntExp = New InternetExplorer
Dim objIntExpDoc As Object
Dim objIntExpDocElmt As Object
Dim wsData As Worksheet
Dim strUsername As Long
Dim strPassword As String
Dim lngDateLast As Long
Dim lngDateCurrent As Long
Dim strSymbol As String
Dim strQuery As String
Dim lngRow As Long
Dim lngLength As Long
Dim lngLastSymbolRow As Long
Const str_LOGIN_PAGE As String = "https://oltx.fidelity.com/ftgw/fbc/ofsummary/defaultPage"
Const str_START As String = "http://research2.fidelity.com/fidelity/screeners/etf/etfholdings.asp?symbol="
Const str_END As String = "&view=Sector"
Const lng_SYMBOL_LENGTH_MIN As Long = 3
Const lng_SYMBOL_LENGTH_MAX As Long = 5
Const lng_SYMBOL_ROW_MIN As Long = 2
Const lng_SYMBOL_ROW_MAX As Long = 21
' Check for a new date
lngDateLast = CLng(wsMain.Cells(5, 3))
lngDateCurrent = CLng(Date)
If lngDateLast >= lngDateCurrent Then
MsgBox "TRY AGAIN", vbOKOnly, "Data is already current!"
Exit Sub
End If
' Delete any existing data sheets
If wbThis.Worksheets.Count > 1 Then
Application.DisplayAlerts = False
For Each wsData In wbThis.Worksheets
If wsData.Name <> "Main" Then
wsData.Delete
End If
Next wsData
Application.DisplayAlerts = True
End If
' Get the last symbol row
lngLastSymbolRow = wsMain.Range("A100").End(xlUp).Row
If lngLastSymbolRow > lng_SYMBOL_ROW_MAX Then
lngLastSymbolRow = lng_SYMBOL_ROW_MAX
End If
If lngLastSymbolRow < lng_SYMBOL_ROW_MIN Then
MsgBox "TRY AGAIN", vbOKOnly, "No ETF Symbols detected in Column-A to process!"
Exit Sub
End If
' Set the Username and Password
strUsername = Trim(CStr(InputBox("Enter your Fidelity Username for login.", "FIDELITY USERNAME")))
strPassword = Trim(CStr(InputBox("Enter your Fidelity Password for login.", "FIDELITY PASSWORD")))
' Next line not required, but helps for debugging
objIntExp.Visible = True
' Go to Fidelity LogIn page
objIntExp.Navigate str_LOGIN_PAGE
Do While objIntExp.Busy: DoEvents: Loop
Do Until objIntExp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
' Login with user inputs
Set objIntExpDoc = objIntExp.Document
Debug.Print "Form = " & objIntExpDoc.forms(0).Name
Set objIntExpDocElmt = objIntExpDoc.getElementByID("userId-select")
objIntExpDocElmt.Value = strUsername
Debug.Print objIntExpDocElmt.Name & " = " & objIntExpDocElmt.Value
Set objIntExpDocElmt = objIntExpDoc.getElementByID("password")
' Note - password disappears here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
objIntExpDocElmt.Value = strPassword
Debug.Print objIntExpDocElmt.Name & " = " & objIntExpDocElmt.Value
objIntExpDoc.forms(0).submit
Do While objIntExp.Busy: DoEvents: Loop
Do Until objIntExp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
' Cycle through all symbols
For lngRow = lng_SYMBOL_ROW_MIN To lngLastSymbolRow Step 1
strSymbol = Trim(CStr(wsMain.Cells(lngRow, 1)))
lngLength = Len(strSymbol)
If (lngLength < lng_SYMBOL_LENGTH_MIN) Or (lngLength > lng_SYMBOL_LENGTH_MAX) Then
' Invalid symbol ... skip it
GoTo GetNextSymbol:
End If
' Build the web query URL
strQuery = str_START & strSymbol & str_END
' Add a new worksheet
wbThis.Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = strSymbol
' Get the raw ETF query data
With wsMain.QueryTables.Add(Connection:=strQuery, Destination:=Worksheets(strSymbol).Range("A1"))
.Name = strSymbol & "_Query"
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
GetNextSymbol:
Next lngRow
' Refresh the date
wsMain.Cells(5, 3) = lngDateCurrent
NormalExit:
Application.DisplayAlerts = True
GoTo Cleanup:
ErrorOut:
MsgBox "Unable to update data!", vbOKOnly, "UPDATE ERROR"
Cleanup:
Application.DisplayAlerts = True
Set objIntExpDocElmt = Nothing
Set objIntExpDoc = Nothing
Set objIntExp = Nothing
Set wsData = Nothing
Set wsMain = Nothing
Set wbThis = Nothing
End Sub
|
|
|
|
|
There were no inputs to my question but (if anyone cares) I did solve this issue with help from some other developers.
1.) Some web sites (Fidelity included) mask the USERNAME and/or PASSWORD user input. If you drill into the source code for these style of HTML INPUT objects, they will have dual <INPUT> ... </INPUT> lines for the same object. One will be unmasked and the other masked. Choose the INPUT object ID defined in the masked input line to pass a value to the object.
2.) My QueryTable.Add line from above was also causing erors. Upon further review of the QueryTable object model, the required RANGE parameter "must be on the worksheet that contains the QueryTable object". I was attempting to add the QueryTable to the MAIN worksheet and extract data to individual DATA worksheets. I revised the code to add the web query to each individual DATA worksheet.
Adios
|
|
|
|
|
My bad - I spoke too soon about solving the login problem.
When my solution above failed, I started poking around the secure Login page source code as I manually entered Username and Password info on the site.
The actual username value in the Masked input control gets stuffed into the Element's "data-unmasked" Attribute. The Element's Value is an altered variation of the username with "*" fillers replacing all but the last three characters. The form will not login without the "data-unmasked" Attribute being set.
It appears I need to:
- find a way to stuff a new value into an empty Element Attribute
... or ...
- revert to use of the error prone SendKeys option to actually type the username into the input control character by character.
Any hints or tips?
|
|
|
|
|
Hi there!
I'm using the HTMLTextbox from here: [^]
And my Question is how can I change the Font, Fontsize, ....
My Usage:
Private Sub Message_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Message.TextChanged
MessageHTML.Text = Me.Message.GenerateHTML
End Sub
as you can see, everytime my Text in Message is changed my HTML code will be generated, and it works great!
For changing the Font I use:
Private Sub FontBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontBox.SelectedIndexChanged
Message.SelectionFont = New Font(FontBox.Text, FontSize.Text.ToString)
End Sub
And for the Size the same:
Private Sub FontSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontSize.SelectedIndexChanged
Message.SelectionFont = New Font(FontBox.Text, FontSize.Text.ToString)
End Sub
But I don't know how to update my MessageHTML Textfield.
Really hope someone can help!
Thanks
|
|
|
|
|
If you have a question about code from an article, use the forum at the bottom of that article. The author of the code is the person most likely to be able to help you with the code they've written.
HTML Text Box Control ⇒ Comments[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
In an existing vb.2010 desktop application, I need to have the users select the vendors they work with plus the access 2013 database file they want to use as input into the application. I need to have the users select these options before they do their normal processing.
Thus to add this feature to the application, which would you do:
- Have a new form setup with only these features, and once these options are selected, have the application then call the existing form that starts the application right now?
- Would you add these selections to the existing startup form, and 'gray out' the options the users are used to having? Once the users pick new selections, then enable the original options to work?
Thus can tell me the following:
- Which option you chose and why,
- Let me know if can you think of other options that would be good to use in this situation?
- Show me the code and/or point me to references that will tell me how to accomplish my goal using the option you selected?
|
|
|
|
|
dcof wrote: Which option you chose and why, Option 2.
Create a form and only create checkboxes that apply for that user. Disabled checkboxes imply that they can be unlocked.
..and they can. Using the "inspect" application from the Windows SDK.
dcof wrote: Show me the code and/or point me to references that will tell me how to
accomplish my goal using the option you selected? Any tutorial that shows how to create controls dynamically and add them to a form. MSDN has them, CodeProject has them, Google knows them.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
dcof wrote: Which option you chose and why I would subscribe to the Shown-event of the "main window" and show the setup form modally there (by using .ShowDialog() instead of just .Show()) which will prevent input to the "main window" while it's being shown. Why: Because it's the easiest way:
Public Class Form1
Public Sub New()
InitializeComponent()
AddHandler Me.Shown, AddressOf Form1_Shown
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs)
Application.DoEvents()
Dim form2 As New Form2()
form2.ShowDialog()
Dim form3 As New Form3()
form3.ShowDialog()
End Sub
End Class
Explanation for Application.DoEvents() in this article:
Immediate display of WinForms using the Shown() event[^]
edit: Just realized I misinterpreted your question slightly. Regarding the actual question, whether to show 1 or 2 "setup forms": I would go for two sequential setup forms. It's more intuitive to the user.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 4-Jun-15 17:04pm.
|
|
|
|
|
Thank you for your answers so far! However I do have the following additional questions to ask you:
- If I create a new form as you suggested, this new form will now be the first form that a user sees. Thus I would set the new form as the startup correct? If so how do you change the startup project? If not, how would I 'wire' this form into the application so that it displays before the current startup form?
- What should I do to make the 'current' startup form display after the user clicks the button on the new modal form? Basically how do I have the new form call the existing startup form?
- On the existing startup form, is there any kind of logic that I would need to change since it is not the startup form any longer? If so would you let me what I need to change and how would I make the applicable coding changes?
|
|
|
|
|
The application surely has some kind of "main form" which is shown after the "setup form" has been confirmed, right? The code I've shown in my previous message would be an excerpt from the "main form" class. The main form loads and becomes visible but immediately shows the first of the two setup forms and after that has been confirmed, the second setup form will be shown. So, if the current setup form is set as the "startup form" in your project settings, you would change that to the main form instead and incorporate my code example to show the setup forms "from within" the main form.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
In a Visual Basic Net 2010 desktop application, I want users to be able to select only of the Access 2013 database files that are located in a network share area. I would like the Access 2013 file names to be in a dropdown list box for the user to be able to select from. I would also like there to be a default Access 2013 file that will be used.
Thus can you show me the code and/or point me to a url (link) that will tell me how to accomplish this goal?
|
|
|
|
|
|
Would you show me the code and/or point me to url(s) or link(s) that give more detailed code examples how on to accomplish the task I am asking about?
|
|
|
|
|
The first link shows how to get a list of (Access) files. The second link how to work with a listbox.
It is general documentation.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello !
I've used this code to open a form :
Dim frm1 As New Myform1
frm1.Show(Me)
How can I do the same thing , when I doesn't know the form's name at design , but only on runtime.
I have a variable that contains the form's name as string :
Dim frmname as string
What can I do ?
Thank you !
|
|
|
|
|
You can use reflection to search for the Type of the Form and then create an instance of it with Activator (Activator has bad performance compared to other methods but for Form-instantiation it won't matter):
Dim formName As String = "Form1"
Dim formType As Type = Assembly.GetExecutingAssembly().GetTypes().[Single](Function(t) t.Name = formName)
Dim form As Form = DirectCast(Activator.CreateInstance(formType), Form)
In case the Form-class is defined in a different assembly than the assembly in which that code is executing you would have to replace GetExecutingAssembly():
Dim formType As Type = Assembly.GetAssembly(someType).GetTypes().[Single](Function(t) t.Name = formName)
..where "someType" is any Type (static notation) that is defined in the same assembly as the Form.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|