|
Ok maybe i wasnt clear cause english is not my main language. We need to consider the 4 números everytime
Ex: a+b+c+d, a+b+c-d, a+b+c*d, a+b+c/d, etc
|
|
|
|
|
So the sequence is:
+ + +
+ + -
+ + *
etc.
I think that is a permutation of 3 out of 4 which is about 64 (a long time since I studied mathematics).
|
|
|
|
|
Exactly and also the numbers chance positivo aswel cause a/b is not the same as b/a
|
|
|
|
|
Sounds like a good candidate for a recursive algorithm.
To get the results for four numbers, you need to combine:
- The first number
+ the results for the other three numbers; - The first number
- the results for the other three numbers; - The first number
* the results for the other three numbers; - The first number
/ the results for the other three numbers;
For example:
Public Shared Function AllResults(ByVal ParamArray numbers() As Integer) As IEnumerable(Of Integer)
If numbers Is Nothing OrElse numbers.Length = 0 Then Return Enumerable.Empty(Of Integer)
Return AllResultsIterator(numbers, numbers.Length)
End Function
Private Shared Iterator Function AllResultsIterator(ByVal numbers As IEnumerable(Of Integer), ByVal length As Integer) As IEnumerable(Of Integer)
Dim n0 As Integer = numbers.First()
If length = 1 Then
Yield n0
Return
End If
For Each result As Integer In AllResultsIterator(numbers.Skip(1), length - 1)
Yield n0 + result
Yield n0 - result
Yield n0 * result
If result <> 0 Then Yield n0 \ result
Next
End Function NB: This will include duplicate results.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh, this looks good, i will try it later. Many many thanks
|
|
|
|
|
First of all apologies if I posted in wrong forum and im a complete newbie to programming so need things idiot proof if you know what I mean.
What I need to do is I have a .vbs of which runs into a .DOS and need to add a few things. The person who wrote the original has since left my work where I got it from .
I have posted below parts of the script where I think it needs to go but if wrong just let me know and I will post the whole script.
1) When it puts it into a folder I need it to ask me to input a password . When password input I then need it to move onto the .VBA command of zipping
2) What I also need is instead of it just creating a 7Z file with the name of zipped.7z I need it to be the same name as what the folder was called originally.
1) Think needs to go here just before where it says "all files moved"...
On Error Goto 0
For Each objFile In objDLFolder.Files
objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next
objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&
dim dotbat
set dotbat=createobject("wscript.shell")
dotbat.Run "C:\Users\icc.cctv\Documents\DONOTDELETE1.bat", 1, True
set dotbat=Nothing
2) I think it needs to go somewhere in there ...
cls&echo ENTER THE STATEMENT INTO FOLDER,
echo THIS WINDOW WILL CLOSE IN 5 SEC.
) else (
cls
7z a -t7z "C:\Downloads\zipped.7z" "C:\Downloads"
echo.&echo ALL FILES MOVED^^!
)
timeout 5 /NOBREAK >nul&exit/b
As said im compleely new so go easy on me please
|
|
|
|
|
glenn masters wrote: 1) When it puts it into a folder I need it to ask me to input a password . When password input I then need it to move onto the .VBA command of zipping You'd want to do that in the VBS part (not VBA, its not an application macro), as that has some easier ways to get user-input than the console has. Use the InputBox Function[^] and put the text into a variable.
glenn masters wrote: 2) What I also need is instead of it just creating a 7Z file with the name of zipped.7z I need it to be the same name as what the folder was called originally. So you'll need the original name of the folder that is being archived, do some string-manipulation probably to remove the path-part, and re-use that name when executing the archiving-command. Again, done from the VBS part; don't start adding it to the project at once; write it in a new VBS and get it working first, then integrate with the solution.
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.
|
|
|
|
|
Hi,
I would need the following encryption/decryption source to work in VB6.
Public Function Encrypt(ByVal plainText As String) As String
Dim passPhrase As String = "1234567890"
Dim saltValue As String = "0987654321"
Dim hashAlgorithm As String = "SHA1"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
Dim plainTextBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
Dim symmetricKey As New RijndaelManaged()
symmetricKey.Mode = CipherMode.CBC
Dim encryptor As ICryptoTransform = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)
Dim memoryStream As New IO.MemoryStream()
Dim cryptoStream As New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
cryptoStream.FlushFinalBlock()
Dim cipherTextBytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
cryptoStream.Close()
Dim cipherText As String = Convert.ToBase64String(cipherTextBytes)
Return cipherText
End Function
Public Function Decrypt(ByVal cipherText As String) As String
Dim passPhrase As String = "1234567890"
Dim saltValue As String = "0987654321"
Dim hashAlgorithm As String = "SHA1"
Dim passwordIterations As Integer = 2
Dim initVector As String = "@1B2c3D4e5F6g7H8"
Dim keySize As Integer = 256
' Convert strings defining encryption key characteristics into byte
' arrays. Let us assume that strings only contain ASCII codes.
' If strings include Unicode characters, use Unicode, UTF7, or UTF8
' encoding.
Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
' Convert our ciphertext into a byte array.
Dim cipherTextBytes As Byte() = Convert.FromBase64String(cipherText)
' First, we must create a password, from which the key will be
' derived. This password will be generated from the specified
' passphrase and salt value. The password will be created using
' the specified hash algorithm. Password creation can be done in
' several iterations.
Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
' Use the password to generate pseudo-random bytes for the encryption
' key. Specify the size of the key in bytes (instead of bits).
Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
' Create uninitialized Rijndael encryption object.
Dim symmetricKey As New RijndaelManaged()
' It is reasonable to set encryption mode to Cipher Block Chaining
' (CBC). Use default options for other symmetric key parameters.
symmetricKey.Mode = CipherMode.CBC
' Generate decryptor from the existing key bytes and initialization
' vector. Key size will be defined based on the number of the key
' bytes.
Dim decryptor As ICryptoTransform = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
' Define memory stream which will be used to hold encrypted data.
Dim memoryStream As New IO.MemoryStream(cipherTextBytes)
' Define cryptographic stream (always use Read mode for encryption).
Dim cryptoStream As New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
' Since at this point we don't know what the size of decrypted data
' will be, allocate the buffer long enough to hold ciphertext;
' plaintext is never longer than ciphertext.
Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.Length - 1) {}
' Start decrypting.
Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
' Close both streams.
memoryStream.Close()
cryptoStream.Close()
' Convert decrypted data into a string.
' Let us assume that the original plaintext string was UTF8-encoded.
Dim plainText As String = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
' Return decrypted string.
Return plainText
End Function
|
|
|
|
|
|
Why are you still using VB6? It is a dead language.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
I'm trying to set NumericUpDown control to Flatsyle.
Setting Borderstyle as FixedSingle effects only to the numberbox.
Is there a way to set also the up/down buttons to flatstyle?
jtpaa
|
|
|
|
|
|
Hi , I'm try to run my VB script which was working fine all the while, but suddenly getting the "Run-time error '9' for Subscript out of range" on my script fro the below code line:
SchemaMandatory = SchemaDetailSplit(2)
The script to take the 3 items:
- Fields
- DataType
- Mandatory
can someone help to advise what I'm missing here
|
|
|
|
|
You are trying to access an array item with an index that is outside the limits of your array. Look at your code and the data. What does SchemaDetailSplit(2) actually return?
|
|
|
|
|
I have this app made in vb6 which use ms access database, when install this app the .mdb file and other files gets store in the app folder i.e. c:\program files\my app\ and my software works fine. But when I install the same installation program in other system or computer the .mdb file gets store in C:\Users\xxx\AppData\Local\VirtualStore\ and its read and update the data from there only. And when trying to export the data to ms-excel its does not get exported though it did not give any error message.
I just wonder what could be the problem with this exporting and the storing the mdb file in this location, I have installed this app on windows 7 system.
Would be very grateful if anyone can give help or suggestion on this.
Thank you
Zela
|
|
|
|
|
Starting with Windows Vista, folder virtualisation has been intruduced. System folders like the program files folder are protected from being used for user files and access is redirected to the VirtualStore of the current user.
But even with older Windows versions it was not recommended to use the program files folder for user data.
Your problem is that the installation program is run with administrative priviliges and can therefore create files and folders in the program files directory. But accesses from the application itself will be redirected to the VirtualStore folder.
That you did not get any error message when the database can't be found is another sign of bad application design (besides storing user data at the wrong place).
If you have access to the source of the application and the installation program you should update both to use a common data folder. The most common is
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
If not, you should ask the developer for an update.
As a last resort, execute the application with administrator priviliges.
|
|
|
|
|
Thank you very much Jochen Arndt for your helpful response. I kind of a little bit understand now how things happen as I run the app with administrator privileges it kind of work now such as extracting data report to ms-excel. The coding is done by me making some modification from code downloaded from the internet.
Well let say it does not matter if the software read the data from virtualstore folder but what i want to make is exporting the data to ms excel. when I run the app through vb without compiling extraction of the data to ms excel works fine. But when I compile it as .exe and run the software, extraction of the data to ms excel works fine in some system but on some system it just does not make any output even though it report as is has done. Could you please guide me on how to rectify this error, since this app is to be utilized by a group of people and if they can't export the report in ms excel it would be kind of useless.
Would be grateful if you could please suggest any idea on this.
Thank you.
|
|
|
|
|
If it is your application use a common folder for the database as already suggested. Than you will have no problems and do it as recommended. All you have to ensure then is that the installation program creates that folder.
|
|
|
|
|
The above error i.e. extracting data to ms excel occurs especially on windows 10, it does not make any extraction at all, but when run the program or the exe file as an admin its work fine, would be grateful if any one help me solve this problem.
Thank you.
|
|
|
|
|
Jochen has already given you the solution; please follow his recommended suggestions.
|
|
|
|
|
The statement he had put up there seems more like a .NET rather than old plain VB6, I need help on VB6 not in .NET
|
|
|
|
|
The answer has nothing to do with either .NET or VB6, it is about how Windows allows access to different folders.
|
|
|
|
|
Hi All,
I create a program that runs on backgound using VB.NET minicap.exe with CMD as process. Inside the code is module and SUB_MAIN with system timers. It works fine except i notice that when my program runs on background as process? The other application on desktop is BLINKING intermittently. the system timer is set to 2sec upto 10seconds. heres my code below.
The main purpose of my program is to capture screenshot of desktop and save to network drive using MINICAP.EXE and CMD and SYSTEM TIMERS.
Imports System.Timers
Imports Microsoft.Win32
Imports MySql.Data.MySqlClient
Module Module1
Private myTimer1 As Timer
Private myTimer2 As Timer
Private myTimer3 As Timer
Private WithEvents MyProcess As Process
Private Delegate Sub AppendOutputTextDelegate(ByVal text As String)
Sub main()
DBconnection()
Dim uname As String
Dim mname As String
Dim Yourpath As String
uname = Environment.UserName
mname = Environment.MachineName
Try
Dim squery As String = "Select * from tbl_settings WHERE Computer = '" & mname & "'"
Dim sadapter As New MySqlDataAdapter
Dim scommand As New MySqlCommand
Dim sqltable As New DataTable
Dim i As Integer
Dim PAT
Dim STAT
Dim INTR
Dim COMPR
Dim x As Integer
With scommand
.CommandText = squery
.Connection = myconnection
End With
With sadapter
.SelectCommand = scommand
.Fill(sqltable)
End With
x = sqltable.Rows.Count
STAT = IIf(sqltable.Rows(i)("Status") IsNot DBNull.Value, sqltable.Rows(i)("Status"), vbNullChar)
If STAT = "ON" Then
COMPR = IIf(sqltable.Rows(i)("Compression") IsNot DBNull.Value, sqltable.Rows(i)("Compression"), vbNullChar)
INTR = IIf(sqltable.Rows(i)("Interval") IsNot DBNull.Value, sqltable.Rows(i)("Interval"), vbNullChar)
PAT = IIf(sqltable.Rows(i)("server_path") IsNot DBNull.Value, sqltable.Rows(i)("server_path"), vbNullChar)
'InputTextBox.Text = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & CAP & " " & "-exit -save" & " " & PAT
Yourpath = PAT & "\" & Format(Now, "MM-d-yyyy") & "\" & mname & "\" & uname
If (Not System.IO.Directory.Exists(Yourpath)) Then 'CHECK IF BUHAY YUNG SHARED DRIVE OR HINDI.. IF HINDI SA LOCAL MUNA
System.IO.Directory.CreateDirectory(Yourpath)
End If
sharedval.InputParam = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & COMPR & " " & "-exit -save" & " " & Chr(34) + Yourpath & "\" & Format(Now, "HH:mm:ss") & ".jpg" & Chr(34)
sharedval.Xcompression = COMPR
sharedval.Xinterval = INTR
sharedval.xServer = Yourpath
myTimer1.Enabled = True
myTimer1.Interval = INTR
ElseIf STAT = "OFF" Then
myTimer1.Enabled = False
End If
COMPR = IIf(sqltable.Rows(i)("Compression") IsNot DBNull.Value, sqltable.Rows(i)("Compression"), vbNullChar)
INTR = IIf(sqltable.Rows(i)("Interval") IsNot DBNull.Value, sqltable.Rows(i)("Interval"), vbNullChar)
PAT = IIf(sqltable.Rows(i)("server_path") IsNot DBNull.Value, sqltable.Rows(i)("server_path"), vbNullChar)
myTimer1.Interval = INTR
'InputTextBox.Text = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & CAP & " " & "-exit -save" & " " & PAT
Yourpath = PAT & "\" & Format(Now, "MM-d-yyyy") & "\" & mname & "\" & uname
If (Not System.IO.Directory.Exists(Yourpath)) Then 'CHECK IF BUHAY YUNG SHARED DRIVE OR HINDI.. IF HINDI SA LOCAL MUNA
System.IO.Directory.CreateDirectory(Yourpath)
End If
sharedval.InputParam = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & COMPR & " " & "-exit -save" & " " & Chr(34) + Yourpath & "\" & Format(Now, "HH:mm:ss") & ".jpg" & Chr(34)
sharedval.Xcompression = COMPR
sharedval.Xinterval = INTR
sharedval.xServer = Yourpath
Catch ex As Exception
'MsgBox(Err.Description & Err.Number)
End Try
'Me.AcceptButton = ExecuteButton
'MyProcess.BeginErrorReadLine()
'MyProcess.BeginOutputReadLine()
'AppendOutputText("Process Started at: " & MyProcess.StartTime.ToString)
myTimer1 = New System.Timers.Timer()
myTimer1.Interval = 2000 ' 2sec
AddHandler myTimer1.Elapsed, AddressOf OnTimedEvent1
myTimer1.AutoReset = True
myTimer1.Enabled = True
myTimer2 = New System.Timers.Timer()
myTimer2.Interval = 60000 ' 2sec
AddHandler myTimer2.Elapsed, AddressOf OnTimedEvent2
myTimer2.AutoReset = True
myTimer2.Enabled = True
myTimer3 = New System.Timers.Timer()
myTimer3.Interval = 2000 ' 2sec
AddHandler myTimer3.Elapsed, AddressOf OnTimedEvent3
myTimer3.AutoReset = True
myTimer3.Enabled = False
MyProcess = New Process
With MyProcess.StartInfo
.FileName = "CMD.EXE"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardInput = True
.RedirectStandardOutput = False
.RedirectStandardError = False
End With
MyProcess.Start()
Application.Run()
End Sub
Private Sub OnTimedEvent1(source As Object, e As System.Timers.ElapsedEventArgs)
Call absolutepath()
MyProcess.StandardInput.WriteLine(sharedval.InputParam)
MyProcess.StandardInput.Flush()
End Sub
Private Sub OnTimedEvent2(source As Object, e As System.Timers.ElapsedEventArgs)
Call checkstatus()
End Sub
Private Sub OnTimedEvent3(source As Object, e As System.Timers.ElapsedEventArgs)
End Sub
Private Sub MyProcess_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.ErrorDataReceived
AppendOutputText(vbCrLf & "Error: " & e.Data)
End Sub
Private Sub MyProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.OutputDataReceived
AppendOutputText(vbCrLf & e.Data)
End Sub
Private Sub AppendOutputText(ByVal text As String)
'If OutputTextBox.InvokeRequired Then
' Dim myDelegate As New AppendOutputTextDelegate(AddressOf AppendOutputText)
' Me.Invoke(myDelegate, text)
'Else
' OutputTextBox.AppendText(text)
'End If
End Sub
Public Sub absolutepath()
sharedval.InputParam = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & sharedval.Xcompression & " " & "-exit -save" & " " & Chr(34) + sharedval.xServer & "\" & Format(Now, "HH:mm:ss") & ".jpg" & Chr(34)
End Sub
Public Sub checkstatus()
Try
DBconnection()
Dim uname As String
Dim mname As String
Dim Yourpath As String
uname = Environment.UserName
mname = Environment.MachineName
Try
Dim squery As String = "Select * from tbl_settings WHERE Computer = '" & mname & "'"
Dim sadapter As New MySqlDataAdapter
Dim scommand As New MySqlCommand
Dim sqltable As New DataTable
Dim i As Integer
Dim PAT
Dim STAT
Dim INTR
Dim COMPR
Dim x
With scommand
.CommandText = squery
.Connection = myconnection
End With
With sadapter
.SelectCommand = scommand
.Fill(sqltable)
End With
x = sqltable.Rows.Count
STAT = IIf(sqltable.Rows(i)("Status") IsNot DBNull.Value, sqltable.Rows(i)("Status"), vbNullChar)
If STAT = "ON" Then
myTimer1.Enabled = True
ElseIf STAT = "OFF" Then
myTimer1.Enabled = False
End If
COMPR = IIf(sqltable.Rows(i)("Compression") IsNot DBNull.Value, sqltable.Rows(i)("Compression"), vbNullChar)
INTR = IIf(sqltable.Rows(i)("Interval") IsNot DBNull.Value, sqltable.Rows(i)("Interval"), vbNullChar)
PAT = IIf(sqltable.Rows(i)("server_path") IsNot DBNull.Value, sqltable.Rows(i)("server_path"), vbNullChar)
myTimer1.Interval = INTR
'InputTextBox.Text = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & CAP & " " & "-exit -save" & " " & PAT
Yourpath = PAT & "\" & Format(Now, "MM-d-yyyy") & "\" & mname & "\" & uname
If (Not System.IO.Directory.Exists(Yourpath)) Then 'CHECK IF BUHAY YUNG SHARED DRIVE OR HINDI.. IF HINDI SA LOCAL MUNA
System.IO.Directory.CreateDirectory(Yourpath)
End If
sharedval.Xcompression = COMPR
sharedval.Xinterval = INTR
sharedval.xServer = Yourpath
'InputTextBox.Text = "minicap.exe -capturedesktop -stderr -noerr -cursor -compress" & " " & COMPR & " " & "-exit -save" & " " & Chr(34) + Yourpath & "\" & Format(Now, "HH:mm:ss") & ".jpg" & Chr(34)
Catch ex As Exception
End Try
Catch ex As Exception
End Try
End Sub
End Module
modified 14-Apr-18 19:52pm.
|
|
|
|
|
If you are capturing images of the screen at regular intervals then you must expect some disruption to the screen display.
|
|
|
|
|
I understand that loading of mouse cursor is normal every interval but interacting with other windows form or programs is not.
|
|
|
|
|