|
I'm not sure what you expect, you are asking for support for a language that has not been supported for more than 20 years!
I know some of us are fossils but you need to understand that memory becomes a problem for the aged (ancient)!
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
|
Hi VB Experts,
I cannot update my data in the Excel and receive this error
Operator '=' is not defined for type for 'DBNull' and string '1'. The following is my codes:
Dim cnn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + str_Database + ";Extended Properties=Excel 12.0;")
Dim cmd = New OleDbCommand()
Dim str_SQL As String = ""
Dim int_Max_SN As Integer
Try
If (tb_SN.Text = "") Then
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT IIF(ISNULL(MAX(VAL([S/N]))), 0, MAX(VAL([S/N]))) FROM [Sheet2$]"
int_Max_SN = cmd.ExecuteScalar()
cnn.Close()
tb_SN.Text = int_Max_SN + 1
str_SQL += "INSERT INTO [Sheet2$] "
str_SQL += "([S/N], [MPN], [Description], [OEM (Manufacturer)], [MTBF (Hours)], [Failure Rate], [Repair Turn Around Time], [Utilization Rate], [Population], [Spares Required], [Testing], [Price Per Unit], [Total Cost Per Line Item]) "
str_SQL += "VALUES (" + tb_SN.Text + ", "
str_SQL += "'" + tb_MPN.Text + "', "
str_SQL += "'" + tb_Description.Text + "', "
str_SQL += "'" + tb_OEM.Text + "', "
If (IsNumeric(tb_MTBF.Text)) Then str_SQL += tb_MTBF.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Failure_Rate.Text)) Then str_SQL += tb_Failure_Rate.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Year_Of_Support.Text)) Then str_SQL += tb_Year_Of_Support.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Utilization_Rate.Text)) Then str_SQL += tb_Utilization_Rate.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Population.Text)) Then str_SQL += tb_Population.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Spares_Required.Text)) Then str_SQL += tb_Spares_Required.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Price_Per_Unit.Text)) Then str_SQL += tb_Price_Per_Unit.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Total_Cost_Per_Line_Item.Text)) Then str_SQL += tb_Total_Cost_Per_Line_Item.Text + ", " Else str_SQL += "null, "
If (IsNumeric(tb_Total_Uptime.Text)) Then str_SQL += tb_Total_Uptime.Text Else str_SQL += "null "
str_SQL += ")"
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = str_SQL
cmd.ExecuteNonQuery()
cnn.Close()
LoadRecords()
MessageBox.Show("New record has been added successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
For int_Row_Index As Integer = 0 To dgv_Excel.Rows.Count - 1
If (dgv_Excel.Rows(int_Row_Index).Cells(0).Value = tb_SN.Text) Then
dgv_Excel.Rows(int_Row_Index).Cells(1).Value = tb_MPN.Text
dgv_Excel.Rows(int_Row_Index).Cells(2).Value = tb_Description.Text
dgv_Excel.Rows(int_Row_Index).Cells(3).Value = tb_OEM.Text
dgv_Excel.Rows(int_Row_Index).Cells(4).Value = IIf(IsNumeric(tb_MTBF.Text), tb_MTBF.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(5).Value = IIf(IsNumeric(tb_Failure_Rate.Text), tb_Failure_Rate.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(6).Value = IIf(IsNumeric(tb_Year_Of_Support.Text), tb_Year_Of_Support.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(7).Value = IIf(IsNumeric(tb_Utilization_Rate.Text), tb_Utilization_Rate.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(8).Value = IIf(IsNumeric(tb_Population.Text), tb_Population.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(9).Value = IIf(IsNumeric(tb_Spares_Required.Text), tb_Spares_Required.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(10).Value = IIf(IsNumeric(tb_Price_Per_Unit.Text), tb_Price_Per_Unit.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(11).Value = IIf(IsNumeric(tb_Total_Cost_Per_Line_Item.Text), tb_Total_Cost_Per_Line_Item.Text, DBNull.Value)
dgv_Excel.Rows(int_Row_Index).Cells(12).Value = IIf(IsNumeric(tb_Total_Uptime.Text), tb_Total_Uptime.Text, DBNull.Value)
int_Row_Index += 1
End If
Next
str_SQL += "UPDATE [Sheet2$] "
str_SQL += "SET [MPN] = '" + tb_MPN.Text + "', "
str_SQL += "[Description] = '" + tb_Description.Text + "', "
str_SQL += "[OEM (Manufacturer)] = '" + tb_OEM.Text + "', "
If (IsNumeric(tb_MTBF.Text)) Then str_SQL += "[MTBF (Hours)] = " + tb_MTBF.Text + ", " Else str_SQL += "[MTBF (Hours)] = null, "
If (IsNumeric(tb_Failure_Rate.Text)) Then str_SQL += "[Failure Rate] = " + tb_Failure_Rate.Text + ", " Else str_SQL += "[Failure Rate] = null, "
If (IsNumeric(tb_Year_Of_Support.Text)) Then str_SQL += "[Repair Turn Around Time] = " + tb_Year_Of_Support.Text + ", " Else str_SQL += "[Repair Turn Around Time] = null, "
If (IsNumeric(tb_Utilization_Rate.Text)) Then str_SQL += "[Utilization Rate] = " + tb_Utilization_Rate.Text + ", " Else str_SQL += "[Utilization Rate] = null, "
If (IsNumeric(tb_Population.Text)) Then str_SQL += "[Population] = " + tb_Population.Text + ", " Else str_SQL += "[Population] = null, "
If (IsNumeric(tb_Spares_Required.Text)) Then str_SQL += "[Spares Required] = " + tb_Spares_Required.Text + ", " Else str_SQL += "[Spares Required] = null, "
If (IsNumeric(tb_Price_Per_Unit.Text)) Then str_SQL += "[Testing] = " + tb_Price_Per_Unit.Text + ", " Else str_SQL += "[Testing] = null, "
If (IsNumeric(tb_Total_Cost_Per_Line_Item.Text)) Then str_SQL += "[Price Per Unit] = " + tb_Total_Cost_Per_Line_Item.Text + ", " Else str_SQL += "[Price Per Unit] = null, "
If (IsNumeric(tb_Total_Uptime.Text)) Then str_SQL += "[Total Cost Per Line Item] = " + tb_Total_Uptime.Text + " " Else str_SQL += "[Total Cost Per Line Item] = null "
str_SQL += "WHERE VAL([S/N]) = " + tb_SN.Text
cnn.Open()
cmd.Connection = cnn
cmd.CommandType = CommandType.Text
cmd.CommandText = str_SQL
cmd.ExecuteNonQuery()
cnn.Close()
MessageBox.Show("Record has been updated successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
End Try
modified 21-Apr-22 11:15am.
|
|
|
|
|
|
Which line is generating that error?
|
|
|
|
|
Hello
I use IsDBNull a lot in my C# codes because I usually add Microsoft.Visualbasic reference to my CSharp codes. The full qualification is Microsoft.VisualBasic.Information.IsDBNull.
The way I use is below:-
<b>if (IsDBNull(MyDt.Rows[0]["StartDate"])) </b>
After retrieving my data into my datatable (MyDt), then I evaluate based on a column (startdate) of the datatable
You usually perform Isnumeric on variable in your code, but you perform IsDBNull on database field.
|
|
|
|
|
MessageBox.Show("New record has been added successfully!!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
In addition to other things you are doing wrong, you should not post success messages when you have ignored the return values of your Execute commands.
|
|
|
|
|
I agree need to know what line is throwing the error.
Can you see what ex.StackTrace shows in your Catch ex as Exception block?
Below lets you create a breakpoint when an error is raised then you can resume to the line giving the error
This is just to help you find your error line - use catch/try/end try otherwise
To debug remove your try, catch, end try then...
On Error GoTo err_handler
quit_proc:
Exit Function
err_handler:
MsgBox Error, vbCritical, CStr(Erl) + " " + CStr(Err)
Resume
|
|
|
|
|
Hello everyone, i am trying to use powershell in vb6 to create directory.However when i run the compiled file, nothing happened.
I am using this code
Shell "cmd.exe /c powershell New-Item \\?\C:\Windows \System32 -ItemType Directory"
Note that, after "\windows there is space between the slash(this is intentional). I even tried with CMD
Dim command As String
command = "md \\?\C:\Windows \System32"
Shell "cmd.exe /c command"
Any suggestions?
|
|
|
|
|
1. Stop using VB6. It's been dead for over 20 years now.
2. The path you specify should not start with "\\?\".
3. The folders should not already exist. Trying to create C:\Windows or C:\Windows\System32 will fail as they already exist.
4. The Windows and Windows\System32 folders are protected from being written to by normal users. Any attempt to create folders or files in these folders will fail.
5. If I remember correctly (I haven't touched VB6 in over 20 years!) you don't even need Shell to do it. You can just do
MkDir "C:\MyFolder"
modified 20-Apr-22 12:26pm.
|
|
|
|
|
Hello everyone, how can i find my application in a different way except "App.Path & "" & App.EXEName"
Any suggestion with API?
|
|
|
|
|
Literally the first result on Google for "VB.NET App.Path[^]":
For that you can use the Application[^] object.
Startup path, just the folder, use Application.StartupPath()[^]
Dim appPath As String = Application.StartupPath() Full .exe path, including the program.exe name on the end:, use Application.ExecutablePath()[^]
Dim exePath As String = Application.ExecutablePath()
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I used this in a windows service before. Try it
string MyAppPath = AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
|
i have data of employee and wants to print all emp data with picture
|
|
|
|
|
Although I do not use Crystal Reports these days again, because I use RDLC reports within Visual Studio.
When I was using Crystal Report in those days, I know they also have field for Image (blob), you can use this to print the picture of the employees.
In RDLC reports that I now use, I did something like that and each staff's picture comes out on the pay slip.
What you can do is to add an image/blob field to your employee table and capture their picture with their basic details at employee information setup, which you can link when reporting. Some people may want to save employee pictures on physical disk, this will be rowdy to me and it is not very safe.
Try image/Blob field in your table and when saving the picture, convert it to bytes. It will be shown in Crystal Report or RDLC, just ensure you bind the column to Crystal Report Blob/Image field.
|
|
|
|
|
Hi to all, I need to write inside a file located in a folder of my account in google drive and I wrote a desktop application in VB.net using Google Driver API v3. Since that me and my friend use the same account in different PC with the same VB.net application that I wrote, I need your help to to check if that file is opened by another user to avoid opening and garantee an "exclusive opening" on it.
I dont' know if google drive as an option to set an "exclusive opening" instead of API.
Maybe I can set permission to "read only" on the file when is opened by my application but I think it is not a good thing because if my application crashes (for example for a blackout) my file remain in read only state for always.
That's my routine that make a connection on my Google drive with my credentials, search for my folder and my file and give me back their ID:
Public Sub GoogleDrive()
Dim credential As UserCredential
Dim ID_Folder As String = ""
Dim ID_File As String = ""
Using Stream = New FileStream("credenzials.json", FileMode.Open, FileAccess.Read)
'The file token.json stores the user's access and refresh tokens, and is created
'automatically when the authorization flow completes for the first time.
Dim credPath As String = "token.json"
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(Stream).Secrets,
Scopes,
"user",
CancellationToken.None,
New FileDataStore(credPath, True)).Result
Console.WriteLine("Credential file saved to: " + credPath)
End Using
'Create Drive API service.
Dim Service = New DriveService(New BaseClientService.Initializer() With
{
.HttpClientInitializer = credential,
.ApplicationName = ApplicationName
})
' Define parameters of request.
Try
Dim findrequest As FilesResource.ListRequest = Service.Files.List()
findrequest.PageSize = 10
findrequest.Fields = "nextPageToken, files(id, name)"
findrequest.Spaces = "drive"
Dim listFolder As Data.FileList = findrequest.Execute()
If listFolder.Files.Count > 0 Then
For Each item In listFolder.Files
If item.MimeType = "application/vnd.google-apps.folder" Then
If item.Name = "MyFolder" Then
ID_Folder = item.Id.ToString
End If
End If
'
If item.MimeType = "application/msaccess" Then
If item.Name = "myFile.mdb" Then
ID_File = item.Id.ToString
End If
End If
If (ID_File <> "") And (ID_Folder <> "") Then
'How check if ID_File is opened by an other user ?
Exit For
End If
Next
End If
Catch ex As Exception
'MsgBox(ex.Message)
Throw ex
End Try
End Sub
Can someone help me ?
|
|
|
|
|
hello everyone how are you, as always asking for your great help that you have given me, it happens that I have a text document, where I can look for information in a text file, if it finds it, assign that value found in a variable to me format of the text that I have is this, the text document contains several names
Example
Text file
aof.zip:Art Of Fighting / Ryuuko no Ken
Search: aof.zip once finder save in a variable the name that is after the :
Show: Art Of Fighting / Ryuuko no Ken
|
|
|
|
|
|
Hey guy, if you are using VB, it has a function called Instr. This function compares the two strings and returns integer value. If the value returned is greater than 0, that means that is the starting position of the word you are searching for, otherwise it will return -1 if not found.
Note:- Ensure you convert the two strings to the same case before comparing(Upper or Lower case characters).
|
|
|
|
|
Either you're using VB6, which has been dead for over 20 years now...
... or you're still using the VB6-compatibility methods in VB.NET code, which is a recipe for poor performance and ugly code.
Also, InStr returns 0 when a match is not found, not -1 .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Of course I stopped using VB like 5 or 6 years ago, but the person that needs help posted it under VB. I use C# and the approach is different in C#.
You answer questions in the context of where it is posted. I will not use C# to answer VB questions, everyone has his own reasons for choosing a language. For the returned value in search string, I used VB last in 2016 or 2017 and I indicated I was not sure what it would return, but either 0 or -1 to indicate it was not contained in the search string.
As we speak, some companies have huge applications they developed in VB6 and they are a major source of income to their companies, are they going to throw them away because we now have Dot Net Core? That will be crazy! So we help to provide solutions in their context.
|
|
|
|
|
There's nothing in the question to indicate that they're using VB6 rather than VB.NET; unless otherwise specified, it's safest to assume the OP is not using a dead language.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Instr function is not specific to VB6, it is also in VB.Net, perhaps you don't know and secondly you should check the forum title. The forum title where we are discussing is Visual Basic, so the reason I suggested VB function to them.
|
|
|
|
|
As I said previously, InStr in VB.NET is a VB6-compatability method. Any VB.NET code written in the last twenty years (as opposed to code migrated from VB6) should be using the far superior methods available on the String class[^].
And just because there aren't separate "VB.NET" and "VB6" forums doesn't mean we should assume all questions posted here refer to a language which has been dead for two decades.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|