I found a fingerprint class in C# here
I'm trying to convert the function below to VB .NET but I am having issues with the line that reads s+ = (char)....Any help would be appreciated.
private static string GetHexString(byte[] bt)
{
string s = string.Empty;
for (int i = 0; i < bt.Length; i++)
{
byte b = bt[i];
int n, n1, n2;
n = (int)b;
n1 = n & 15;
n2 = (n >> 4) & 15;
if (n2 > 9)
s += ((char)(n2 - 10 + (int)'A')).ToString();
else
s += n2.ToString();
if (n1 > 9)
s += ((char)(n1 - 10 + (int)'A')).ToString();
else
s += n1.ToString();
if ((i + 1) != bt.Length && (i + 1) % 2 == 0) s += "-";
}
return s;
}
Is there a better way to write this function in VB.NET?
This
s += ((char)(n1 - 10 + (int)'A')).ToString();
is the same as
s &= Chr((n1 - 10 + Asc("A")))
Related
I am trying to find the Time complexity from the lines of code. However, I am not really getting it.
int codeMT(int n) {
int a = 1;
int i = 1;
while (i < n * n) {
j = 1;
while (j < n * n * n) {
j = j * 3;
a = a + j + i;
}
i = i + 2;
}
return a;
}
In this case, this is my thought process.
Firstly, we need to start from the inner loop.
while (j < n * n * n) {
j = j * 3;
a = a + j + i;
}
In here, there is j = j * 3 which makes this log(n)(log base 3) but then we have a loop guard that has nnn which makes the n^3. Therefore, this part of code has log(n^3) time complexity.
Secondly, the outer while loop has the loop guard of n * n which makes it n^2.
Thus, O(n^2(log(n^3))
Is my approach okay? or is there anything that I am missing/things that I could improve my thought process?
Thank you
I have to import some data in my Shipment table from .csv file,but i have problem with imorting DATE.
Here is you can see my generator:
class Shipment extends Generator
{
private String snd_time;
private String dliv_time;
private int deliv_id;
private int post_id;
int d, m, y, rnd;
public Shipment() throws FileNotFoundException, Exception
{
PrintWriter wr = new PrintWriter("ShipmentData.csv");
for(int i = 1; i < 100001; i++){
m = 1 + r.nextInt(12);
y = 2005 + r.nextInt(16);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
d = 1+r.nextInt(31);
if(m == 4 || m == 6 || m == 9 || m == 11)
d = 1 + r.nextInt(30);
if((y % 4 == 0) && m == 2)
d = 1 + r.nextInt(29);
if((y % 4 ) != 0 && m == 2 )
d = 1 + r.nextInt(28);
if(m >= 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
snd_time = "0" + Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
snd_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
snd_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
rnd = 1 + r.nextInt(7);
if(m == 1 || m == 3 || m ==5 || m ==7 || m ==8 || m ==10 || m ==12)
{
if((d + rnd) > 31 ) {
d = (d + rnd) - 31;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 31)
d += rnd;
}
if(m == 4 || m == 6 || m == 9 || m == 11)
{
if((d + rnd) > 30) {
d = (d + rnd) - 30;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 30)
d += rnd;
}
if((y % 4 == 0) && m == 2)
{
if((d + rnd) > 29) {
d = (d + rnd) - 29;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 29)
d += rnd;
}
if((y % 4 ) != 0 && m == 2 )
{
if((d + rnd) > 28) {
d = (d + rnd) - 28;
m++;
if(m > 12) {
m = 1;
y++;
}
}
if((d + rnd) < 28)
d += rnd;
}
if(m >= 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + Integer.toString(m) + "/" + Integer.toString(y);
if(m < 10 && d < 10)
dliv_time = "0" + Integer.toString(d) + "/" /*+ "0"*/ + Integer.toString(m) + "/" + Integer.toString(y);
if(d < 10 && m >= 10)
dliv_time = "0" + Integer.toString(d) + "/" + Integer.toString(m) + "/" +Integer.toString(y);
if(m < 10 && d >= 10)
dliv_time = Integer.toString(d) + "/" + "0" + Integer.toString(m) + "/" + Integer.toString(y);
deliv_id = 1 + r.nextInt(100000);
post_id = 1 + r.nextInt(100000);
wr.println(i + "," + this.snd_time + "," + this.dliv_time + "," + this.deliv_id + "," + this.post_id );
}
wr.close();
}
}
Here is my ctl file:
LOAD DATA
INFILE 'D:\databaseProject\Data\ShipmentData.csv'
INSERT INTO TABLE shipment
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
id,
send_time,
deliv_time DATE "dd/mm/yyyy",
delivery_id DATE "dd/mm/yyyy",
post_id
)
but when i load this ctl file i get this error
Record 4: Rejected - Error on table SHIPMENT, column SEND_TIME.
ORA-01843: not a valid month
I've tried to write my date without 0, but it still doesn't work and i cannot find a solution for my problem
I have developed the excel using the Apache NPOI dll using HSSFWORKBOOK. But in my excel having 3 dependent dropdowns one in each other.
Here my question is I am unable to clear the cell value of dependent dropdowns. Let say like dropdown1 have country values and on the selection of this dropdown2 state values got a filter and selected one of the state. Now if I changed the country again able to filter the data but whatever the previous state selection not getting cleared.
code ref:
No, i am just referring the list of columns data from sheet2 to sheet1 using the formulae. below is code ref:
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//if (i >= MaxRowCount)
//{
// sheet2.CreateRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
// MaxRowCount += 1;
//}
//else
// sheet2.GetRow(1000 + i).CreateCell(1).SetCellValue(ds.Tables[0].Rows[i][1].ToString());
if (CategoryCount == 250)
{
rownumber = rownumber + 3000;
CategoryCount = 16;
MaxRowCount = 0;
}
DataRow[] DR = ds.Tables[1].Select("LOCATION_ID=" + ds.Tables[0].Rows[i][0].ToString());
int RowCount = 0;
//int rownumber = 1000;
foreach (DataRow d in DR)
{
if (RowCount >= MaxRowCount)
{
sheet2.CreateRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
MaxRowCount += 1;
}
else
{
sheet2.GetRow(rownumber + RowCount).CreateCell(CategoryCount).SetCellValue(d[0].ToString());
}
RowCount++;
}
IName DeptHierarchy_Dept = hssfworkbook.CreateName();
DeptHierarchy_Dept.NameName = "XDeptHierarchy_Dept_SUB" + (XDeptHierarchy_Dept_SUBCount).ToString();
if (CategoryCount / 26 < 1)
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + CategoryCount)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + CategoryCount)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
else
DeptHierarchy_Dept.RefersToFormula = "'Template Field Specs2'!$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + (StartRowNumber + 1) + ":$" + ((char)(65 + (CategoryCount / 26) - 1)).ToString() + ((char)(65 + CategoryCount % 26)).ToString() + "$" + ((StartRowNumber + 1) + (RowCount == 0 ? 0 : RowCount - 1)).ToString();
CategoryCount++;
XDeptHierarchy_Dept_SUBCount++;
You are looking for "Dependent Drop Down Lists". You'll have to be creative for your formula because your row will keep changing.
one approach i can think of is store the list of "Country-capital" on named region some where deep in excel. On selection of country, parse and find the capital from named region and populate your target cell.
Please see the documentation.
Also this link;
I am attempting to get the following code working for a Fibonacci shift register to generate pseudo-random numbers. Can't seem to get it working, so is(are) there any obvious issues(?)
Shared Function Main() As Integer
Dim start_state As UShort = &HACE1UI ' Any nonzero start state will work.
Dim lfsr As UShort = start_state
Dim bit As UInteger
Dim period As UInteger = 0
Do While lfsr <> start_state
' taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1
bit = ((lfsr >> 0) Xor (lfsr >> 2) Xor (lfsr >> 3) Xor (lfsr >> 5)) And 1
lfsr = (lfsr >> 1) Or (bit << 15)
period += 1
Loop
Return 0
End Function
Last, does "period" need to be divided by a large integer to get U(0,1)'s?
Below is the original C++ code:
# include <stdint.h>
int main(void)
{
uint16_t start_state = 0xACE1u; /* Any nonzero start state will work. */
uint16_t lfsr = start_state;
uint16_t bit; /* Must be 16bit to allow bit<<15 later in the code */
unsigned period = 0;
do
{
/* taps: 16 14 13 11; feedback polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
lfsr = (lfsr >> 1) | (bit << 15);
++period;
} while (lfsr != start_state);
return 0;
}
As in #dummy's comment,
Do While lfsr <> start_state
...
Loop
doesn't run because lfsr = start_state at the beginning.
The code equivalent to C++
do {
...
} while (lfsr != start_state);
in VB.NET is
Do
...
Loop While lfsr <> start_state
How to do the "a++" and "b++" in Visual basic?
What is the another codes for there in Vb?
The names there are just example.
int a = 0;
int b = 0;
{
if (ans1.Text == "James")
{
a++;
}
else
{
b++;
}
if (ans2.Text == "Ryan")
{
a++;
}
else
{
b++;
}
if (ans3.Text == "Mac")
{
a++;
}
else
{
b++;
}
t1.Text = a.ToString();
t2.Text = b.ToString();
}
Like this:
a += 1
b += 1
(...)
Like this
DIM a as integer = 0
DIM b as integer = 0
If ans1.Text = "James" Then
a += 1
Else
b += 1
End If
If ans2.Text = "Ryan" Then
a += 1
Else
b += 1
End If
If ans3.Text = "Mac" Then
a += 1
Else
b += 1
End If
t1.Text = a.ToString()
t2.Text = b.ToString()
Your question has already been answered but I think it would be useful to see how you could simplify your code:
Dim correctAnswers As Integer = 0
Dim totalQuestions As Integer = 3'you need to modify this is you add more questions
'increment the number of correct answers for each one we find
correctAnswers += If(ans1.text = "James", 1, 0)
correctAnswers += If(ans2.text = "Ryan", 1, 0)
correctAnswers += If(ans3.text = "Mac", 1, 0)
'show the number of correct and incorrect answers
t1.Text = correctAnswers.ToString()
t2.Text = (totalQuestions - correctAnswers).ToString() 'show the number of incorrect questions
Neither the postfix nor prefix ++ are defined in Visual Basic.
Your only realistic option is to use a = a + 1 (or, in later BASICs, a += 1) instead (note the lack of a ; for a statement terminator). But note that this will not evaluate to the previous value of a and the entire construct is not an expression in the C / C++ sense. You could build a function to mimic a++ but that would be too obfuscating.