Which object is null?
The debugger is your friend - use it to see.
Which object is null?
The debugger is your friend - use it to see.
Auto incrementing ids work this way by design. If you want more control then use a column you can explicitly control.
Database Replication is one term for synching databases - particularly when talking about SQL Server. Not sure about the other term - could be multi tenant?
Youre welcome.
Ok cool, this is what I said right from the start!
The following should guide you with some ideas. Its is not a solution to your problem but an example of what you can do. It should be enough to get you going.
In terms of converting a string into a ListBox, you cannot. They are not compatible. Its like saying convert some paint into a car. You can paint a car with paint but you cannot turn one into the other.
You cannot turn a string into a ListBox. A ListBox is a comlex object with many properties, methods and events. You can however populate a ListBox with items in your string.
Which UI are you using - Winforms?
using System;
using System.Globalization;
using System.Linq;
namespace ForEach
{
class Program
{
static void Main(string[] args)
{
try
{
Test("111\n222\n333", "222");
Test("111\n222\n333", "111");
Test("111\n222\n333", "444");
Test("111\t222\t333", "111");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadKey();
}
private static void Test(string s, string removeString)
{
var filteredString = RemoveItem(s, "222", '\n');
foreach (var line in filteredString.Split('\n'))
{
if (line == "333")
{
Console.WriteLine("Found the 333 number");
}
}
}
static string RemoveItem(string s, string removeString, char seperator)
{
if (!s.Contains(seperator))
{
throw new ArgumentException("The target string does not contain any instances of the supplied seperator");
}
if (String.IsNullOrEmpty(s))
{
return s;
}
var cleanedString = String.Join(seperator.ToString(CultureInfo.InvariantCulture), s.Split(seperator).Where(i => i != removeString));
return cleanedString;
}
}
}
Thanks diafol that's an interesting post.
The thing that really bugs me though is that whatever technique you use involving prototypes to simulate classes and facilitate code reuse, you have to do it in many lines of disjointed code. You cannot do it in one function. This just stinks in terms of SRP and makes code a monolithic mess of spaghetti which is difficult to understand and difficult to maintain.
Hence the reason for this post and my original question in the first place.
I think the reality is we just have to accept that JavaScript is a pile of crap but we are stuck with it so we may as well at least try and understand how it works, even if we don't like what we find!
Show me the design of the table in the GUI please.
I often find some guys either annoying or funny, it's a fine line sometimes.
Why is it so complicated? Good question! Let me know if you figure it out!
Youre welcome.
You don't actually need that ToArray as Split returns an array already, don't know why I put that on.
foreach (var line in s.Split('\n'))
<a href="http://www.success.com"><img class="headlineimage" id="img1" src="success.jpg" width="200" height="150" /></a>
You can change the href with code too.
Here is one way.
using System;
using System.Linq;
namespace ForEach
{
class Program
{
static void Main(string[] args)
{
const string s = "111\n222\n333";
foreach (var line in s.Split('\n').ToArray())
{
if (line == "333")
{
Console.WriteLine("Found the 333 number");
}
}
Console.ReadKey();
}
}
}
Does CryptoStream implement IDisposable?
If so then wrap that in a using statement too.
So after that, does the code actually work?
@Maurits - just looked at your curly braces on new line issue.
I do know to not put these on new lines for my return statements eg:
return {
breathe: breathe,
eat: eat
};
I will always put them on a new line for function declarations though as I have always done that in all curly braced langauges I have used (C, C++, Pascal, Java, C#, JavaScript etc) and it is a preferred style of mine. I find it easy to line the two up with my eye to see where things start and end which is particularly useful with many nested levels.
Also sorry I also don't like the space between function and () idea either. If you can't see whether a function is being defined or called then you are in a whole lot of trouble. Also it would drive my OCD crazy. I know this is just a style issue but I don't like it but each to their own I think.
In my Animal, Cat example, if Animal were to be a kind of abstract class and I would only ever be creating Cats, Dogs etc then I suppose it doesn't matter that I didn't create my Animal functions via it's prototype - as long as I set my Cat and Dog to have an Animal as it's prototype then there won't be any issues of functions repeating again and again in memory. I think that sounds right, does everyone agree with that?
Yep its a great video.
I have learned a lot today but still a way to go I think!
That's ok JavaScript is the most confusing language ever.
I used to think I must be stupid as I couldn't understand JavaScript but now realise it doesn't even understand itself!
instanceof does work fine again unless you are using the revealing module pattern.
I'm quite happy with prototyping - that is I'm not against it but I just don't like how you cannot do it all inside the one function. That kind of annoys me and drives my OCD crazy!
If you have some spare time and want proof that JavaScript is crazy check this video out, it's very funny too.
Hi AleMonteiro, JavaScript is always fun!
The code below shows that t.breathe IS equal to s.breathe
You can see it running here:
http://www.paxium.co.uk/content/RevealingModuleTests/Test002.html
Its only when you use the Revealing Module pattern that this is not true.
In any case the functions are always going to be logically equal, the only possible issue is whether in memory we have one of them per object or a shared one. I don't know how JavaScript deals with this under the hood but unless we have a lot of instances of something I don't see this ever being an issue.
<script>
function Animal()
{
function privateFunction()
{
alert("I m private");
}
function breathe()
{
alert("I am breathing");
}
function eat()
{
alert("I am eating");
}
}
var t = new Animal();
var s = new Animal();
alert(t.breathe === s.breathe);
</script>
I'm studying JavaScript all day today so hopefully my posts will get better throughout the day!
Ok sorry my apologies.
This should be really easy and to repeat my first reply to this thread, just debug the code and see what is happening.
Have you done this or not? It should be the very first thing you should ever do when something like this doesn't work.
Sorry I thought you said it was working now? Is it working or not?
Hi
Thanks for your comments, all very interesting and useful.
If I question what you have written, it is not intended to be argumentative but rather just the way I learn - if I don't understand something I question it until I do!
Ok so a lot to discuss here so lets do them one at a time so the thread is more manageable.
So lets look at the style in which I declared Animal. My creation of animal was pureley to give me something to be the protoytpe of Cat. This was my area of research so other issues, whilst important, were not really my focus.
I believe the style in which Animal is written is a variation of the Revealing Module pattern which is intended to hide properties and functions in an attempt to mimic classical inheritance a little. I understand what you are saying about making your intentions visble by using an underscore. So it seems there are two schools on this. Are you saying that the Revealing Module pattern is just plain wrong then?
I think the reason that alert(t.breathe === s.breathe); is false is because my Animal function does not return an Animal it all - it returns an anonymous object. I don't think you need to actually use prototype to setup an Animal. You can do it as below and then the functions are equal.
<script>
function Animal()
{
function privateFunction()
{
alert("I m private");
}
function breathe()
{
alert("I am breathing"); …
A friend just showed me this way - any thoughts on that?
var Cat = function()
{
var m = new Animal();
m.purr = function ()
{
alert("Purr purr");
};
return m;
};
Have you debugged or echoed to see that the actual SQL statements resovle to?
Also in your example the private function is not private. I can go:
joey.breathe();
joey.eat();
joey._privateFunction();
I got the pattern I am using in my original post off a friend and I think he uses it to hide private functions this way.
Thanks Maurits - looks interesting, I shall have a tinker.
I have a few different patterns for creating prototypes but why do you think the one above is bad?
I am tinkering with prototypal inheritance in JavaScript.
I have the code below and I am trying to find out if there is a way of getting the code which makes Cat inherit Animal actually inside the Cat function - so that it is all niceley encapsulated as one unit of code.
The line in question is:
Cat.prototype = new Animal();
Any ideas if this is possible?
<script>
function Animal()
{
function privateFunction()
{
alert("I m private");
}
function breathe()
{
alert("I am breathing");
}
function eat()
{
alert("I am eating");
}
return {
breathe: breathe,
eat: eat
};
}
function Cat(name, age)
{
this.name = name;
this.age = age;
}
Cat.prototype = new Animal();
var joey = new Cat("Joey", 5);
joey.breathe();
joey.eat();
</script>
Where did user_id come from? I don't see that in your code which builds up the sql statement.
Can you debug this and show what the SQL statement parses out to please?
I like the first one, was only joking about the / though!
Did you change the data being insrted/updated?
You really need to understand how http works under the hood for this kind of thing.
Its too much to cover in a textbox on a forum like this. You would be much better off spending some time watching some videos. This one for example is quite good:
This error message means you are trying to insert or update data which is too long.
Eg trying to enter "Dave" into a database column defined as only being 3 characters in length.
Decrease your data or increase your column width.
It just means you are declaring a variable called flag and giving it a value of 1 or 0. This will presumably be used elsewhere in the code to keep a track of the state of something. It is also probably boolean in nature.
Read a book, watch some videos, take a class, find a provate tutor, read a website.
The above advice also applies to T in HowToLearn<T>
Hi Thomas
I don't code in C++ but in C# we would do this with a static property.
I do think you may be misunderstanding inheritance.
Could you post the simplest version possible of code needed to demonstrate what you are trying to achieve and I can comment further.
Its badly formed, should be />
:)
Can't beat a vodka water cooler in the office
Can't you just debug it and see. Do you know how to debug and step through code?
Ok you will need image recognition software then in case someone tries to inject some brie or red leicester by mistake.
Yep or Vodka O'Clock
What is Foto - is that some kind of goats cheese?
smug mode engaged Youre welcome smug mode cancelled
I sent the food back and cancelled.
I just so knew they would bring the same food back later rather than cooking it fresh so I cancelled.
Had a nice salmon pasta bake instead :)
Ok I am going to attempt to solve this even without seeing your code even though that goes against my scientific nature.
Do you by any chance have JavaScript thinking your variables are strings and not numbers?
Did you do something like this maybe?
http://www.paxium.co.uk/content/daniweb/ifstatement.html
<body>
<script>
$(document).ready(function()
{
var maxGrootte = $("#t1").val();
var minGrootte = $("#t2").val();
if(maxGrootte < minGrootte)
{
alert(maxGrootte + " is less than " + minGrootte);
}
else
{
alert(maxGrootte + " is not less than " + minGrootte);
}
});
</script>
<input type="text" id="t1" value="12" />
<input type="text" id="t2" value="5" />
</body>
Show me your code though please - there is something wrong with it but I can't fix it unless you show it to me.
Sure - I wrote an article on this
http://www.paxium.co.uk/PublicArticle/Article/497
If that's too much to read just at least do this:
using (MemoryStream stream = new MemoryStream())
//Code goes here
}
It is far more likeley that you have done something wrong.
For example you have two spellings of minGrooote there. One with one t and one with two ts.
Can you show me the code where you declare and assign values to these two variables?
Antony, this is a serious question...
Do you think we can give you an answer to this without knowing your database schema?
Ha ha keep em coming!