|
All of us must have come across the fact that some set of codes are specific to a particular OS only and incompatible with others. In some instances they may also lead to system crashes.
In such cases we need to track and identify the OS first and then proceed accordingly. So, here is how you can write a program in VB6.0 that can run in different Windows operating systems.
http://www.mindfiresolutions.com/Determining-host-operating-system-using-VB-6-189.php
Cheers,
Eliza
|
|
|
|
|
All very nice, but if you have to go back to the dark ages with VB6 then you should also handle windows millenium edition, windows 98, possibly windows 95 and variants of NT.
If this is to be of any use going forward you also need to support Windows 7.
Nowhere do you cover the server editions, which is an absolute must!
Plus of course you can get all this out of the box with .Net, and seeing as vb6 is definately a legacy language now, why bother.
|
|
|
|
|
NIce and all, but VB6 is a dead language and you're about 15 years too late to the party with this. The forums is also not the place to post such snippets. Post this in Tips/Tricks instead.
|
|
|
|
|
You can use "winmgmts" like this:
Private Sub Form_Load()<br />
strComputer = "."<br />
Set objWMIService = GetObject("winmgmts:" _<br />
& "{impersonationLevel=impersonate}!\\" _<br />
& strComputer & "\root\cimv2")<br />
Set colSettings = objWMIService.ExecQuery _<br />
("Select * from Win32_OperatingSystem")<br />
For Each objOperatingSystem In colSettings <br />
Label1.Caption = objOperatingSystem.Name<br />
Next<br />
End Sub
More properties in: http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx
Hope be helpful
|
|
|
|
|
each time I run the follow code I get a runtime error.
Public Class menuitems
Public menuitem As String
Public itemcost As Double
End Class
'Dim totalorderquantity(12) as Integer
Public Class frmtodayscafe
Inherits System.Windows.Forms.Form
Public dr As DataRow
Public item() As menuitems
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fileNamex As String = "menu1.txt"
Dim dirName As String = _
Path.GetDirectoryName(Application.ExecutablePath)
Dim dt As DataTable
Dim adapter1 As New OleDbDataAdapter
Using cn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;" & _
"Data Source=" & dirName & ";" & _
"Extended Properties=""Text;HDR=Yes;FMT=Delimited""")
' Open the connection
cn.Open()
' Set up the adapter
Using adapter As New OleDbDataAdapter( _
"SELECT * FROM " & fileNamex, cn)
dt = New DataTable("menuitems")
adapter.Fill(dt)
End Using
End Using
Redim item(dt.Rows.Count() - 1)
Dim drcounter As Integer = 0
For Each dr As datarow In dt.Rows
Debug.Print("{0} {1}", _
dr("Menu Items"), _
dr("Item Cost"))
item(drcounter).menuitem = dr("Menu Items").ToString
item(drcounter).itemcost = dr("Item Cost").ToString
drcounter += 1
Next
the run time error is Object reference not set to an instance of an object.
modified on Friday, March 19, 2010 6:50 PM
|
|
|
|
|
you never set the bounds on item() .
you need a
ReDim Preserve item(drcounter)
...or you could just do
Redim item(dt.Rows.Count() - 1)
|
|
|
|
|
Thanks, It worked. I used
Redim item(dt.Rows.Count() - 1)
to resolve issue after reading the data table.
|
|
|
|
|
glad it worked. Most of the time, we just need a separate set of eyes on our code. I can't tell you how many times I've gotten errors because I forgot a simple line of code.
|
|
|
|
|
compile-time errors and run-time exceptions tend to provide line numbers (assuming a debug build), so you should be able to easily find where the problem occurs, and then deduce where it originated.
|
|
|
|
|
resolved by William Winner
|
|
|
|
|
We have programs that require escalated privilege for certain small tasks as writing to HKEY/LOCAL_MACHINE for our own security keys.
Vista/Win 7 makes this very difficult. We do not want our apps to always to run as admin but only for the short time when we need to write out the HKEY/LM.
What is the way to do this programmatically? I do not mind if the user is asked to confirm or enter a password just need to be able to do it. I did see something about a ShellExecute "runas" but I rather not have another program. I would rather have it in 1 program.
Any ideas?
Thanks
|
|
|
|
|
QBTeKcom wrote: What is the way to do this programmatically?
You can't. I haven't seen anything that will allow you to do this. Either your app runs as an admin or it doesn't. Also, this only works if the user running it has an admin account available. An app cannot give itself more rights than the user that launched it already has.
|
|
|
|
|
QBTeKcom wrote: Any ideas?
have a post on vista/windows7 forum , might get some solution there. SOFTDEV
If you have knowledge, let others light their candles at it. [ Let's work to help developers, not make them feel stupid ]
|
|
|
|
|
Yeah I think you can only have an application run entirely as admin or not. You could probably do it by creating a separate project and spawning it from your current project - running it as admin. That might require creating a batch file that starts the new project with elevated privileges and running that batch file from your original project. Or there might be a way to do it when you spawn a new process - System.Diagnostics.Process.Start. There is an msdn article on it: http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/5a66c921-0d9c-483f-af3f-afa7f3e3b9c1[^]
|
|
|
|
|
Hello all,
I have been pulling my hair our trying to get this to work.
I created a DataSource programatically and applied it to a DataGridView.
Now, I want to add rows to that DataSource programatically and have it displayed in the DataGridView, but I can't for the life of me work out how to add to the DataSource....
I know there must be a relatively simple way to do this..
I can't add data to it in the usual way because the DataGridView is bound.
Any advice is much appreciated! =)
Here's the code for creating the DataSource and adding columns to it on form.load, and showing it in my DataGridView (named "dg"). This part of the code works fine:
Dim Table1 As DataTable
Table1 = New DataTable("Useful Links")
'------------------------------------------------------------
Dim adModel As DataColumn = New DataColumn("adModel")
adModel.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(adModel)
Dim unId As DataColumn = New DataColumn("unId")
unId.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(unId)
'------------------------------------------------------------
Dim ds As New DataSet()
ds.Tables.Add(Table1)
dg.DataSource = Table1
'------------------------------------------------------------
There will be a button (or something) to add rows to that DataSource.modified on Wednesday, March 17, 2010 9:14 PM
|
|
|
|
|
|
Thanks for the response but this doesn't appear to be what I'm after...
I am no expert (particularly with datatables) but the method you suggested appears to require a DataSet.
Like mentioned earlier, my data is created at runtime (called Table1) on form.load so I am unsure how to refer to it programmatically...
Forgive me if I am not making sense, or going the wrong way about all this, as previously mentioned I am not disciplined in datatables!
|
|
|
|
|
it is easy use like this
Dim dsObj As CRDataSet = New CRDataSet ' Your DataSource Here
dsObj.tablename.addmaintablerow(str1,str2,str3)If you can think then I Can.
|
|
|
|
|
If you're just binding the DGV to a single table, with no relations to other tables, you don't even need the DataSet. A DataSet is just a collection of DataTable object and DataRelations between them.
Since your DGV is bound to a DataTable, you just need to add a new row to the DataTable, not to the DGV. Look into the DataTable.NewRow method.
An alternative to doing it manually would be to create a BindingSource object, set it's DataSource to your DataTable, then set the DGV's DataSource to the BindingSource you created. All navigation and row handling is handled by the BindingSource object.
|
|
|
|
|
Thanks for the explanation Dave, that helped alot.
Gonna try a few of your suggestions now and see how I go
|
|
|
|
|
I have an application that has a tab control and on each tab there is a button that runs a process, I have set up the process to run on a separate thread which kind of works. I can rig it to work the way I want for testing but not the way it should work. Basically I want to Click the button to run the process and then be able to navigate to another tab do other work and when the process finishes to update the tab from which it was called while I'm on a different tab. This works if I hard code the tabindex in the SetText sub. I should mention the tabs are created dynamically on demand by the user at run time from a template class. I will list the code segments below and will show the rigged working code as well below my issues. Here are my issues.
1. Application Crashes(encountered a problem and has to close) when I attempted either of statement Only when the new thread calls the procedure that contains this code.
a) If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
b) EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
2. I need to capture the tab index that started the new thread because when the thread returns the info and I need to update the textbox from "SetText" on the tab from which the thread was called. Since the tabs are Dynamically created from a template they all have textboxes with the same name in this case "txtMaxAddr".
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
3. Can I run a separate thread on each tab? i.e. on a tab click the button to run the process switch another tab click the button run the process for that tab... etc...
--------
Public Class CreateTab
Public Function ReadTab(ByRef tpRead As TabPage, ByVal dgCurrentRow As DataGridViewRow)
.
.dynamicaaly created code is here
.
'btnMax
'
btnMax.Location = New System.Drawing.Point(285, 6)
btnMax.Name = "btnMax"
btnMax.Size = New System.Drawing.Size(109, 23)
btnMax.TabIndex = 15
btnMax.Text = "Match to Account"
btnMax.UseVisualStyleBackColor = True
AddHandler btnMax.Click, AddressOf Form1.btnMax_Click
.
.
.
End function
End Class
Private demoThread As Thread = Nothing
Delegate Sub SetTextCallback(ByVal [text] As String)
-
Private Sub dgInbox_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgInbox.CellDoubleClick
Dim iTabCount, iIndex As Integer
If TabControl1.TabPages.ContainsKey(dgInbox.CurrentRow.Cells(0).Value.ToString()) = False Then
TabControl1.TabPages.Add(dgInbox.CurrentRow.Cells(0).Value.ToString(), Mid(dgInbox.CurrentRow.Cells(2).Value.ToString(), 1, 25))
Me.tpRead.SuspendLayout()
CreateTab.ReadTab(TabControl1.TabPages.Item(TabControl1.TabPages.Count - 1), dgInbox.CurrentRow)
Me.tpRead.ResumeLayout(False) Me.tpRead.PerformLayout()
TabControl1.SelectTab(TabControl1.TabPages.Count - 1) 'set to currently displayed tab
Else
iIndex = TabControl1.TabPages.IndexOfKey(dgInbox.CurrentRow.Cells(0).Value.ToString())
TabControl1.SelectTab(iIndex) ' tab already was created diplay it
End If
End Sub
-
Public Sub btnMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMax.Click
'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
' Create a thread and start it.
Me.demoThread = New Thread(New ThreadStart(AddressOf Me.CallMax))
Me.demoThread.Start()
End Sub
-
Public Sub CallMax()
Dim AccountInfo As String
'1. Issue #1b
EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
MaxConn.LinkToAccount(EmailAddr, AccountInfo)
Dim NewText As String = AccountInfo
'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
'1. Issue #1a
If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
'It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[NewText]})
Else
' It's on the same thread, no need for Invoke.
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText]
End If
'=====
End Sub
-
Private Sub SetText(ByVal [text] As String)
'2. Issue number 2
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
End Sub
--Rigged to work---
Public Sub CallMax()
Dim AccountInfo As String
'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
MaxConn.LinkToAccount(EmailAddr, AccountInfo)
Dim NewText As String = AccountInfo
'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
'1. Issue #1
'If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
'It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[NewText]})
'Else
' It's on the same thread, no need for Invoke.
'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText]
End If
'=====
End Sub
-
Private Sub SetText(ByVal [text] As String)
'2. Issue number 2
'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
TabControl1.TabPages(3).Controls("txtMaxAddr").Text = [text]
End Sub Thanks in advance for any help!
dotnetme2
|
|
|
|
|
I haven't looked at all that code, here are a few answers and comments:
1.
If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
your intentions are good, you are aware you can't just touch Controls from any thread other than the one that created them; but what about TabControl1.SelectedIndex and TabControl1.TabPages ? Those parts of the statement are also touching Controls. That is were your problem is coming from.
The solution is rather easy: I assume the TabControl, its TabPages, and all their Controls all were generated by the same thread, hopefully the main thread (a.k.a. GUI thread). If so, it does not really care which of all those you use to check InvokeRequired on, so just do:
If TabControl1.InvokeRequired Then
2.
it may be simpler to encapsulate the calculations you want performed "on a tab" as you called it, inside their own class; a little class that holds its job parameters, holds some events, creates its Thread or BackgroundWorker, and launches them. Then create handlers for the tab, and wire them to the job class's events so it knows how to return results.
Doing it that way, the job classes don't have to know about TabControls and TabPages; they do the work without being aware of the GUI, all they know is initial parameters and a way to report back.
|
|
|
|
|
|
I am trying to write a user control that displays graphical squares on a drawn grid
I have the graphics side of it working fine but need to use a custom array to give me the data to plot the squares
here's my array
Public Structure SatChar
Public SatNr As Integer
Public SatAxim As String
Public SatElev As String
Public SNR As String
End Structure
Public Shared arrSatChars(0 To 35) As SatChar
how do i set this array into a property???
I have tried
Protected arrSatChars(0 To 35) As SatChar
Public Property Satellites(ByVal SatNr As Integer, ByVal SatAxim As String, ByVal SatElev As String, ByVal SNR As String) As SatChar()
Get
Return arrSatChars
End Get
Set(ByVal value As SatChar())
arrSatChars = value
Me.Refresh()
End Set
End Property
but this doesnt work
im still new to vb.net and any help would be much appreciated
thank youmodified on Wednesday, March 17, 2010 9:41 PM
|
|
|
|
|
Probably something more like this:
Private _arrSetChars() As SatChar
Public Property Satellites(ByVal index As Integer) As SatChar
Get
Return _arrSatChars(index)
End Get
Set(ByVal value As SatChar)
_arrSatChars(index) = value
End Set
End Property
Note: There is no bounds checking in this code. This is just a small framework upon which to build.
|
|
|
|