Q:
VBA - toString() with a list of objects
I have a list of different objects. Each object has some informations (String, Number) that I need to send to the database and I have to make sure they are sorted by a certain condition.
The list looks like this:
Dim listitems As New List
listitems.Add "String1", "Number1"
listitems.Add "String2", "Number2"
listitems.Add "String3", "Number3"
I have already made a function that sorts a list and gives me a new list of objects:
Public Function SortList(ByRef _list As List) As List
Dim _last As Long
Dim _temp As ListItem
If _list.Count > 0 Then
For _last = _list.Count - 1 To 1 Step -1
_temp = _list(_last)
If _temp.Value _list(_last + 1).Value Then
_list(_last) = _temp
_list(_list.Count - 1) = _temp
End If
Next
End If
SortList = _list
End Function
I want to send this list to the database by using the DB.Put() method, but this one works only with string:
Dim objStrng As String
objStrng = "String1"
DB.Put "listitems", "Value", objStrng
A:
First of all, why don't you use the built-in OrderBy method? Here's an example for you:
Dim listitems As New List
listitems.Add "String1", "Number1"
listitems.Add "String2", "Number2"
listitems.Add "String3", "Number3"
Dim listordered As List = listitems.OrderBy(Function(l) l.Value)
DB.Put "listitems", "Value", listordered
Is this what you want to do? If so, you don't need your own method.
Second, and this is important, you don't use List as the 01e38acffe
Jack McBain is the Head of Business Development at Precision Construction Services and is responsible for business development and strategic business partnerships.
Download istram ispol crack torrent.rar
Aidan Quinn is our Director of Business Development and is responsible for identifying new clients and delivering and maintaining business relationships with existing clients.
Download istram ispol crack torrent.rarQ:
Django: Query by model field in view
I have two models (simplified example):
class Model1(models.Model):
value1 = models.IntegerField()
class Model2(models.Model):
name = models.CharField()
value = models.IntegerField()
Model1 contains a value1 field which is the unique identifier of the Model2 object.
In a Django view, I want to get a queryset of Model1 objects based on the value in the Model1.value1 field. The example below obviously doesn't work:
queryset = Model1.objects.filter(Model1.value1=1)
Obviously it works if you have a reference object with the value1 field, but I don't. I can do:
my_id = Model1.objects.all().filter(pk=1).first().value1
queryset = Model1.objects.filter(value1=my_id)
But it seems hacky and not at all elegant. Is there a better way to do this?
A:
queryset = Model1.objects.filter(value1=1)
should work. But if you need get only one, use get
queryset = Model1.objects.get(value1=1)
BTW, your solution may fail, if value1 is duplicate.
Q:
How do I sum up all numbers in an array of numbers
So far, I am having trouble doing this with an array of numbers.
The array in this case is
1.1 2.2 3.3
The output should be:
4.4
This is the code I have so far
public class testingArrays {
public static void main(String[] args) {
double[] nums = {1.1, 2.2
Related links:
Comments