VisualBasic - View object in the listbox in ListView - vb.net

I decided to program a simple application. And I need advice. I must point out that I'm a complete beginner, yesterday I started with VB ...
I have a listbox:
Code:
listUzivatelu.Items.Clear ()
listUzivatelu.Items.AddRange (databaze.VratVsechny ())
And I needed it to appear in the ListView:
Code:
Dim TempStr (1) As String
TempStr (0) = "1111"
TempStr (1) = "Doe, John"
ListView1.Items.Add (New ListViewItem (TempStr))
But when I write databaze.VratVsechny () so it just throws an error.
databaze.VratVsechny() returns:
Code:
Public Function VratVsechny () As Product ()
Return Vyrobek.ToArray ()
end Function
I'm attach source code: https://www.dropbox.com/s/btg5c66wvafo8qj/csv-zapis-a-cteni-objektu.zip
Thanks in advance for any advice on the topic.

I tried to run your project, the only problem appeared when executing this line:
databaze.Nacti()
And after digging to the method, I found that error caused by parsing "invalid" string to DateTime. Date strings in csv file appear in date.month.year format, when I edited csv to use month.date.year it parsed successfully and the program run with no error. Another alternative is to use ParseExact instead of Parse method. For Example:
Dim registrovan = DateTime.ParseExact(rozdeleno(2), "d", CultureInfo.CreateSpecificCulture("ru-RU"))
That will successfully parse your current date string in csv, because date format in Russian culture is dd.mm.yy.

Related

How to convert 'Integer' to 'Timestamps'?

**I did a effort but got error while testing
Error BC30311 Value of type 'Integer' cannot be converted to 'Timestamps'.**
I have tried this :
Public Sub test()
client = New DiscordRpcClient("test")
client.Logger = New ConsoleLogger
client.Initialize()
client.SetPresence(New RichPresence With {
.Details = "test",
.Assets = New Assets() With {
.LargeImageKey = "test",
.LargeImageText = "test",
.Timestamps = 0
})
Dim timer = New System.Timers.Timer(150)
AddHandler timer.Elapsed, Sub(sender, args)
client.Invoke()
End Sub
timer.Start()
client.Invoke()
End Sub
here the problem is "Timestamps = 0", So how can i solve.
im trying to use discord rich Presence elapsed timer.
This is actually more of an issue with this Discord-RPC-Csharp library than it is with C#. That being said, I looked into it anyway.
The example code given in the repository for this project shows this as an example
Timestamps = Timestamps.FromTimeSpan(10)
See the error you got is an error specific to C# for when trying to assign one value type to a complete different type. An Integer is not a Timestamp, and a Timestamp is not an Integer. So we need to figure out what Timestamps actually is. So the best way to do this is to right-click on Timestamps and go to "Go To Definition" or hit F12 on it.
Now in RichPresence.cs you can see the class definition for Timestamps. You will see four options
Timestamps.Now
Timestamps.FromTimeSpan(double seconds)
Timestamps.FromTimeSpan(Timespan timespan)
in addition to a constructor
new Timestamps(DateTime start, DateTime end)
Since you haven't told us what this timestamp is supposed to represent in your code, I'll leave it to you to figure out which one of these you want/need to use.

Using Visual Studios 2013 and VB.net, how to capitalize lets in a textfield mixed with numbers

I am and entry level programmer and i have a task that is asking me to modify a page that takes and entry from a textfield that is mixed with letters and numbers. this field is called a "job#" and then the page will search a database for that in particular job. problem is that it only searches it if its in capital letters. need to have it accept caps and lower case letters. it is in VB.net. and i went to the controller and i have this code here
Try
res.success = True
res.message = ""
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber)
Dim req = New ViewModels.Business.Capital.CapitalRequest(r)
Models.Core.Approvals.AddIApprovableToCache(r)
res.data = req
Return New PCA.Core.Web.JSON.JSONPResult() With { _
.Data = res,
.Callback = callback
}
i tried to tack on "ToUpper() after the (jobnumber) because i thought that is where it takes the number entered and applies it to a variable to search the database for it. but it says that 'ToUpper()' is not a member of 'Trident.Objects.Business.Capital.CapitalRequest' im assuming the parent class doesnt have the package where ToUpper() is ?
i tried to tack on "ToUpper() after the (jobnumber) because i thought
that is where it takes the number entered and applies it to a variable
to search the database for it. but it says that 'ToUpper()' is not a
member of 'Trident.Objects.Business.Capital.CapitalRequest'
Instead of
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber).ToUpper()
use
Dim r = New Objects.Business.Capital.CapitalRequest(jobNumber.ToUpper())

How to append Text at the begining of a file?

I'm using the command IO.File.AppendAllLines("3.txt", "text", System.Text.Encoding.Default)
to write to 3.txt.
But the string is writing in down.
How I can write a string upper?
Call the strings ToUpper method to make the string upper case
IO.File.AppendAllLines("3.txt", "text".ToUpper(), System.Text.Encoding.Default)
The .Append() method will always append(add) the given string to an existing content. so n this case you cannot do like this.
I suggest you to read the content first, write the content back to the file along with the additional string. If you are expecting this, then the following code will help you:
var currentContent= File.ReadAllText(#"D:\3.txt");
File.WriteAllText(#"D:\3.txt", "Some string" + currentContent);
// here you are adding "Some string" at the begining of the file

Linqpad - Outputting into anchor to use title

I have a db that stores exception messages.
I would like to create a query that gets these exceptions but instead of dumping huge amounts of text i would prefer it to be "on demand".
I figured putting the exception into an anchor tag like so and then reading the message when needed by mousing over it would work... apparently not.
var logsForErrors = (from error in Logs
select new {
error = LINQPad.Util.RawHtml("<a title='"+ error.Exception+"'></a>"),
errorDate = error.Date,
errorMessage = error.Message
}).Take(10);
logsForErrors.Dump();
This is throwing an exception (lol) - "Cannot parse custom HTML: "
Encoding the exception message
...RawHtml("<a title='"+ Uri.EscapeDataString(error.Exception)+"'></a>")
Message Could not translate expression 'RawHtml((("h__TransparentIdentifier0.error.Exception)) +
"'>"))' into SQL and could not treat it as a local expression.
will generate a new error
Any ideas? - I am open to alternative solutions to this also.
I just want a container for the message instead of it just dumping right into the output as it it so huge!.
Thanks,
Kohan
Have you tried using the "Results to DataGrids" mode in the recent betas? It might do just what you need without having to write anything else.
Edit: your error was probably due to emitting HTML without escaping the text. The easiest solution is to call Util.RawHtml with an XElement instead of a string. You could write an extension method that does what you want like this:
public static class Extensions
{
public static object Tooltipize (this string data)
{
if (string.IsNullOrEmpty (data) || data.Length < 20) return data;
return Util.RawHtml (new XElement ("span", new XAttribute ("title", data), data.Substring (0, 20)));
}
}
Put this into My Extensions and you can use it from any query.

Instantiating a function

This question is about a different instance that im trying to instantiate...
I have to get the "Read" function from my Cardreader class and return a string to it on the form1.vb .... Now i did what i can remeber but for some reason i'm having a problem with the brackets.... What can i do to fix this?
Form1.vb
ThisATM.getCardReader.Readr("TEST TEXT IS FUN")
CardReader.vb
Public Function Readr(ByVal card As KeyCard) As String
Return Read
End Function
Link for the image of the card reader function. I thought this link of the image of the code would be easier to understand.
The Readr function takes an KeyCard as parameter, not an string. So it seems like you have to create an instance to an KeyCard and use that as a parameter instead. In the code in the image you provided you are creating a keycard object, it seems like you should use that object in the Readr function like this:
Dim ThisKeyCard as new KeyCard("1234","5678","Mikki Monster")
Dim returnString as string=ThisATM.getCardReader.Readr(ThisKeyCard)