|
|
Hi,
Where can I find the version like on winver(cmd command) on the office it is 1511 but some registrysettings only exists from 1607 so I want to check if the version is ok.
I found those:
Dim OSVer As Version = Environment.OSVersion.Version
Dim versie = My.Computer.Info.OSVersion
But thats not the info I need.
Jan
|
|
|
|
|
In the console, I'd use "ver", not "winver"; the latter would open a UI, the first one just prints the version to stdout.
Any program you run on the console, can also be started from your application, where you can fetch the results in a string.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
OK, look at the Build property of the Version object you're getting back.
To enable all the versions to be available and not just knocked back to Windows 8, add an Application Manifest file to the application. Open that file, go down the compatibility section, and uncomment all the O/S GUID's:
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
Once you have the build number, compare that build to the list here[^] and you'll find which version of Windows you're running on.
modified 4-Sep-18 10:15am.
|
|
|
|
|
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
'If there is no search string, no rows, or nothing in this cell, then get out.
If ComboBox1.Text = String.Empty Then Return
If (e.Value Is Nothing) Then Return
If e.RowIndex < 0 Or e.ColumnIndex < 0 Then Return
e.Handled = True
e.PaintBackground(e.CellBounds, True)
'Get the value of the text in the cell, and the search term. Work with everything in lowercase for more accurate highlighting
Dim str_SearchTerm As String = ComboBox1.Text.Trim.ToLower
Dim str_CellText As String = DirectCast(e.FormattedValue, String).ToLower
'Create a list of the character ranges that need to be highlighted. We need to know the start index and the length
Dim HLRanges As New List(Of CharacterRange)
Dim SearchIndex As Integer = str_CellText.IndexOf(str_SearchTerm)
Do Until SearchIndex = -1
HLRanges.Add(New CharacterRange(SearchIndex, str_SearchTerm.Length))
SearchIndex = str_CellText.IndexOf(str_SearchTerm, SearchIndex + str_SearchTerm.Length)
Loop
' We also work with the original cell text which is has not been converted to lowercase, else the sizes are incorrect
str_CellText = DirectCast(e.FormattedValue, String)
' Choose your colours. A different colour is used on the currently selected rows
Dim HLColour As SolidBrush
If ((e.State And DataGridViewElementStates.Selected) <> DataGridViewElementStates.None) Then
HLColour = New SolidBrush(Color.DarkGoldenrod)
Else
HLColour = New SolidBrush(Color.Yellow)
End If
'Loop through all of the found instances and draw the highlight box
For Each HLRange In HLRanges
' Create the rectangle. It should start just underneath the top of the cell, and go to just above the bottom
Dim HLRectangle As New Rectangle()
HLRectangle.Y = e.CellBounds.Y + 2
HLRectangle.Height = e.CellBounds.Height - 5
' Determine the size of the text before the area to highlight, and the size of the text to highlight.
' We need to know the size of the text before so that we know where to start the highlight rectangle
Dim TextBeforeHL As String = str_CellText.Substring(0, HLRange.First)
Dim TextToHL As String = str_CellText.Substring(HLRange.First, HLRange.Length)
Dim SizeOfTextBeforeHL As Size = TextRenderer.MeasureText(e.Graphics, TextBeforeHL, e.CellStyle.Font, e.CellBounds.Size)
Dim SizeOfTextToHL As Size = TextRenderer.MeasureText(e.Graphics, TextToHL, e.CellStyle.Font, e.CellBounds.Size)
'Set the width of the rectangle, a little wider to make the highlight clearer
If SizeOfTextBeforeHL.Width > 5 Then
HLRectangle.X = e.CellBounds.X + SizeOfTextBeforeHL.Width - 6
HLRectangle.Width = SizeOfTextToHL.Width - 6
Else
HLRectangle.X = e.CellBounds.X + 2
HLRectangle.Width = SizeOfTextToHL.Width - 6
End If
'Paint the highlight area
e.Graphics.FillRectangle(HLColour, HLRectangle)
Next
'Paint the rest of the cell as usual
e.PaintContent(e.CellBounds)
End Sub
|
|
|
|
|
Dear friends
i write a vb program. in this program a string "john????". and in string count char "?".
thanks ^^
|
|
|
|
|
A string is a sequence of characters with known length. So all you have to do is getting each character from the string, compare it, and upon a match increment a counter variable which has been defined before and initialised with zero.
The above description breaks your requirement down in a way that each part corresponds to a single line of code.
Because this looks like homework, I will not give you code. Try it yourself using my description.
|
|
|
|
|
Find the length of the string, then replace the search character with an empty string, then check the length again. The difference between the two lengths is the number of the characters in the original string. Doing it this way is usually much quicker than testing each character in turn, especially for longer strings.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Are you sure?
The replace function has to do the same iterating job internally. It will also create a new string instance when any replacement occurs. And you would have to use the Replace(String, String) method which is slower than operations on characters.
If speed cares I would use String.IndexOf(Char, Integer) within a while loop instead.
|
|
|
|
|
IndexOf is still going to have to compare every character, and has the added overhead of multiple method calls and argument validation.
Your original suggestion of iterating over the characters in the string would probably have the best performance (unless you start introducing unsafe code).
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Try it - you'll be surprised. Native functions and methods such as String.Replace are highly optimized and will be much faster than while loops and string comparisons.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
I expected them to be highly optimised. My point was that Replace() is creating a new instance and operates on strings rather than characters (the Char version can't be used to remove characters).
IndexOf() is a native function too. On x86 machines the search can be performed with a single CPU instruction: scasw . So this will be faster than a normal loop comparing each character (which is still the expected answer for such homework assignments). If it is finally faster than using Replace() depends on the number of matches.
|
|
|
|
|
It will be highly dependent on the length of the strings. I had reason to write such a function a while back in tSQL for a database system and using the native Replace functionality was much more efficient than looping in all but the shortest of strings, but YMMV.
Module Module1
Sub Main()
Dim iCount As Integer
Dim strToSearch As String = "Every instance. Replace() will inteiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiirnally loop throughiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii the entire source string. It replaces all occurrences of the substring you want to replace. Tip: This behavior is useful when dealing with common string replacements in programs. But: If you do not understand this behavior you may end up writing inefficient code that has unneeded loops. "
Dim strSearchFor As String = "i"
Console.WriteLine(strToSearch)
iCount = strToSearch.Length() - strToSearch.Replace(strSearchFor, "").Length
Console.WriteLine("There are " + iCount.ToString() + " letter " + strSearchFor + "'s in the string")
End Sub
End Module
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Using BenchmarkDotNet[^]:
public class StringCharCountBenchmark
{
private static readonly string _theStringToSearch = "Every instance. Replace() will inteiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiirnally loop throughiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii the entire source string. It replaces all occurrences of the substring you want to replace. Tip: This behavior is useful when dealing with common string replacements in programs. But: If you do not understand this behavior you may end up writing inefficient code that has unneeded loops. ";
private static readonly char _theCharToFind = 'i';
private static readonly string _theCharToFindAsString = "i";
[Benchmark]
public int UsingReplace()
{
return _theStringToSearch.Length - _theStringToSearch.Replace(_theCharToFindAsString, "").Length;
}
[Benchmark]
public int UsingForEachLoop()
{
int result = 0;
foreach (char c in _theStringToSearch)
{
if (c == _theCharToFind)
{
result++;
}
}
return result;
}
[Benchmark]
public int UsingForLoop()
{
int result = 0;
for (int i = 0; i < _theStringToSearch.Length; i++)
{
if (_theStringToSearch[i] == _theCharToFind)
{
result++;
}
}
return result;
}
} (Yes, I know: C#. But I'm sure you can convert to VB.NET if required. )
Results:
// * Summary *
BenchmarkDotNet=v0.11.1, OS=Windows 10.0.17134.228 (1803/April2018Update/Redstone4)
Intel Core i7-4770K CPU 3.50GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
Frequency=3417969 Hz, Resolution=292.5714 ns, Timer=TSC
[Host] : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3132.0
DefaultJob : .NET Framework 4.7.2 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3132.0
Method | Mean | Error | StdDev |
----------------- |-----------:|----------:|----------:|
UsingReplace | 3,923.6 ns | 15.267 ns | 12.749 ns |
UsingForEachLoop | 350.1 ns | 4.453 ns | 3.948 ns |
UsingForLoop | 376.1 ns | 7.239 ns | 8.046 ns |
Both loop options are fairly close. The String.Replace version takes roughly 10x as long.
The tool doesn't measure the memory usage, but it should be fairly self-evident that the Replace version will use more memory, since it has to allocate a new string each time.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Module Module1
Sub Main()
Dim strToSearch As String = "john????"
Dim strSearchFor As String = "?"
Console.WriteLine(strToSearch)
Console.WriteLine("There are " + CountOccurrences(strToSearch, strSearchFor).ToString() + " occurrences of " + strSearchFor + " in the string")
End Sub
Function CountOccurrences(strStringToSearch As String, strStringToCount As String) As Integer
Dim iCount As Integer
iCount = strStringToSearch.Length() - strStringToSearch.Replace(strStringToCount, "").Length
Return iCount
End Function
End Module
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
There is no alternative to filecopy that returns the percentage of files copied during the copy, since opening the file in binary mode is not necessary because the put and get commands are probably due to an overflow since I operate on 2GB files up.
|
|
|
|
|
There is no alternative built into VB6.
You're either going to have to code up your own version in something else that can be exposed to COM and handle 64-bit offsets, like in C#/VB.NET/C/C++, or just have the Shell copy files for you. In that case, you'll end up with the Explorer progress window, just as if you dragged and dropped a file to copy by hand.
|
|
|
|
|
And how do you make a copy with the shell, what command you have to run, and then shows the progress bar with the percentage of files copied?
|
|
|
|
|
|
Thanks a lot even though it was better if I did it with my PROGRess bar and with the instruct put and get opening it in binary....
|
|
|
|
|
You simply don't have that option in your own code because VB6 is 32-bit only and the largest integer it can handle is 2,147,483,647. That makes offsets into a file a max of 2.147GB.
|
|
|
|
|
I writ in italian(with percentage):
private Sub Form_Load()
'KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Ret As Long
'set the graphics mode to persistent
Me.AutoRedraw = True
'print some text
Me.Print "Click the form to abort the filecopy"
'show the form
Me.Show
'start copying
Ret = CopyFileEx("c:\verybigfile.ext", "c:\copy.ext", AddressOf CopyProgressRoutine, ByVal 0&, bCancel, COPY_FILE_RESTARTABLE)
'show some text
Me.Print "Filecopy completed " + IIf(Ret = 0, "(ERROR/ABORTED)", "successfully")
End Sub
Private Sub Form_Click()
'cancel filecopy
bCancel = 1
End Sub
'in a module
Public Const PROGRESS_CANCEL = 1
Public Const PROGRESS_CONTINUE = 0
Public Const PROGRESS_QUIET = 3
Public Const PROGRESS_STOP = 2
Public Const COPY_FILE_FAIL_IF_EXISTS = &H1
Public Const COPY_FILE_RESTARTABLE = &H2
Public Declare Function CopyFileEx Lib "kernel32.dll" Alias "CopyFileExA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As Long, lpData As Any, ByRef pbCancel As Long, ByVal dwCopyFlags As Long) As Long
Public bCancel As Long
Public Function CopyProgressRoutine(ByVal TotalFileSize As Currency, ByVal TotalBytesTransferred As Currency, ByVal StreamSize As Currency, ByVal StreamBytesTransferred As Currency, ByVal dwStreamNumber As Long, ByVal dwCallbackReason As Long, ByVal hSourceFile As Long, ByVal hDestinationFile As Long, ByVal lpData As Long) As Long
'adjust the caption
Form1.Caption = CStr(Int((TotalBytesTransferred * 10000) / (TotalFileSize * 10000) * 100)) + "% complete..."
'allow user input
DoEvents
'continue filecopy
CopyProgressRoutine = PROGRESS_CONTINUE
End Function
Trovato qui(restituisce pure la percentuale) https://www.experts-exchange.com/questions/20743248/Problem-Writing-Reading-a-File-2GB-HELP.html
testato con 10 gb di piu' fatelo voi ma dovrebbe funzionare,mi fido!!!!
|
|
|
|
|
Dear All,
Please help me in providing this solution.
I have just learned Microsoft Visual Basic. Net 2015 with SQL Server 2014.
One problem in update command method, I have prepared the program like this :
Dim i As Integer
Dim update1 As String = ("update datamahasiswa set no= ’" & TextBox1.Text & "’ where nama= ’" & TextBox2.Text & "’")
Try
Me.Validate()
Me.LatihanDataSetBindingSource.EndEdit()
Me.LatihanDataSet.Tables(0).Rows(1).Item(1) = TextBox1.Text
i = DatamahasiswaTableAdapter1.Update(LatihanDataSet.datamahasiswa)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show("no of rows updated=" & i)
The message shown up, like this :
update requires a valid update command when passed data row collection with modified rows. It means : the update method does not run well.
When I insert the command Executequery, this is not enlisted in VB.net
Please help me,
Thank you for your time and attention,
My best regards,
Muljanto
modified 6-Aug-18 7:45am.
|
|
|
|
|
Don't use string concatenation to generate SQL commands. Apart from leaving you wide open to SQL Injection Attacks[^], you can introduce other errors.
Use Parameterized queries instead: see Query Parameterization Cheat Sheet - OWASP[^]
So you would have some code like this
Dim update1 As String = ("update datamahasiswa set no= @parm1 where nama=@parm2") and then some code to add the parameters.
Note I have not included the single quotes ( ' ) in the sql to surround the variable name. You have actually used a ’ character - which is not the same as ' . Using parameterised queries removes errors like that.
|
|
|
|
|
You have not connected your update1 string to your table adapter. So your call to DatamahasiswaTableAdapter1.Update has nothing to work from.
|
|
|
|
|